/* ==========================================
   RECEIPT MANAGEMENT APP - STYLES
   ========================================== */

:root {
  --primary-color: #2c3e50;
  --secondary-color: #3498db;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
  --warning-color: #f39c12;
  --light-bg: #ecf0f1;
  --border-color: #bdc3c7;
  --text-color: #2c3e50;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: #ffffff;
  color: var(--text-color);
  overflow: hidden;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* ========== Layout ========== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#app-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

header {
  background: var(--primary-color);
  color: white;
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

header .header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-logo {
  height: 80px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
}

.header-logo-small {
  height: 45px;
  width: auto;
  object-fit: contain;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

header .header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

header .user-info {
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

header button {
  background: var(--secondary-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.3s;
}

header button:hover {
  background: #2980b9;
}

main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ========== Authentication Screen ========== */
#auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
}

#auth-screen .header-logo {
  height: 120px;
  width: auto;
  margin-bottom: 1rem;
}

#auth-screen h2 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  text-align: center;
}

#auth-screen p {
  font-size: 1.1rem;
  margin-bottom: 2rem;
  text-align: center;
  max-width: 500px;
  opacity: 0.9;
}

#auth-screen .auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 300px;
}

.btn-login {
  background: white;
  color: var(--primary-color);
  padding: 1rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-lg);
}

.btn-login:active {
  transform: scale(0.98);
}

#auth-screen .error {
  background: var(--danger-color);
  color: white;
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 2rem;
  text-align: center;
}

/* ========== Tab Navigation ========== */
nav.tabs {
  display: flex;
  flex-direction: row;
  background: white;
  border-bottom: 2px solid var(--light-bg);
  flex-shrink: 0;
  gap: 0;
}

nav.tabs button {
  flex: 1;
  padding: 1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-color);
  border-bottom: 3px solid transparent;
  transition: all 0.3s;
  white-space: nowrap;
  min-width: 0;
}

nav.tabs button.active {
  color: var(--secondary-color);
  border-bottom-color: var(--secondary-color);
  background: var(--light-bg);
}

nav.tabs button:hover {
  background: var(--light-bg);
}

/* ========== Content Area ========== */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* ========== Upload Section ========== */
#upload-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  gap: 1.5rem;
  text-align: center;
}

.upload-area {
  width: calc(100% - 2rem);
  max-width: 500px;
  padding: 3rem 1rem;
  border: 3px dashed var(--secondary-color);
  border-radius: 12px;
  background: #f8f9fa;
  cursor: pointer;
  transition: all 0.3s;
  margin: 3rem auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.upload-area:hover {
  background: var(--light-bg);
  border-color: var(--secondary-color);
  transform: scale(1.02);
}

.upload-area.dragover {
  background: var(--light-bg);
  border-color: var(--success-color);
  box-shadow: 0 0 10px rgba(39, 174, 96, 0.3);
}

.upload-area p {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0.5rem 0;
}

.upload-area small {
  color: #7f8c8d;
  display: block;
  margin: 0.25rem 0;
  font-size: 0.9rem;
}

.upload-area .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

#file-input {
  display: none;
}

.upload-progress {
  width: 100%;
  max-width: 500px;
  margin: 3rem auto 0;
}

.upload-progress .progress-bar {
  width: 100%;
  height: 8px;
  background: var(--light-bg);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.upload-progress .progress-fill {
  height: 100%;
  background: var(--success-color);
  width: 0%;
  transition: width 0.3s;
}

.upload-result {
  width: 100%;
  max-width: 500px;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  margin: 1rem auto 0;
}

.upload-result.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.upload-result.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* ========== Receipts Section ========== */
#receipts-section {
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.receipts-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.receipts-header select {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}

.receipts-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

/* Grid layout only for month view */
.receipts-list.months-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  grid-auto-rows: max-content;
}

.receipts-header-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--light-bg);
}

.back-link {
  color: var(--secondary-color);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.3s;
  white-space: nowrap;
}

.back-link:hover {
  color: var(--primary-color);
  text-decoration: underline;
}

.receipts-table-container {
  overflow-x: auto;
  margin: 1rem 0;
}

.receipts-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.receipts-table thead {
  background: var(--light-bg);
  font-weight: 600;
  border-bottom: 2px solid var(--border-color);
}

.receipts-table th {
  padding: 0.75rem;
  text-align: left;
  color: var(--text-color);
  font-size: 0.9rem;
}

.receipts-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--light-bg);
}

.receipts-table tbody tr:hover {
  background: #f8f9fa;
}

/* Actions column */
.receipts-table td:last-child {
  white-space: nowrap;
  min-width: 220px;
}

.receipt-item {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: all 0.3s;
}

.receipt-item:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.receipt-item.month {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  flex-direction: column;
}

.receipt-item.month:hover {
  transform: scale(1.05);
}

.receipt-item.month .month-label {
  font-size: 1.2rem;
  font-weight: 600;
}

.receipt-item.month .file-count {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0.5rem 0;
}

.receipt-item.file .file-name {
  font-weight: 600;
  color: var(--text-color);
  word-break: break-word;
  margin-bottom: 0.5rem;
}

.receipt-item.file .file-info {
  font-size: 0.85rem;
  color: #7f8c8d;
  margin-bottom: 1rem;
}

.receipt-item.file .file-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-small {
  padding: 0.4rem 0.8rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  display: inline-block;
  margin-right: 0.5rem;
  white-space: nowrap;
}

.btn-small:last-child {
  margin-right: 0;
}

.btn-download {
  background: var(--secondary-color);
  color: white;
}

.btn-download:hover {
  background: #2980b9;
}

.btn-delete {
  background: var(--danger-color);
  color: white;
}

.btn-delete:hover {
  background: #c0392b;
}

.btn-back {
  background: var(--warning-color);
  color: white;
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.btn-back:hover {
  background: #e67e22;
}

/* ========== Loading & Status ========== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--secondary-color);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--light-bg);
  border-top-color: var(--secondary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.status-message {
  padding: 1rem;
  border-radius: 4px;
  text-align: center;
  margin: 1rem;
}

.status-message.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.status-message.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.status-message.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* ========== Empty State ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: #7f8c8d;
  text-align: center;
}

.empty-state .icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

/* ========== Modal ========== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--light-bg);
}

.modal-header h3 {
  margin: 0;
  color: var(--text-color);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-color);
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--danger-color);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body img,
.modal-body iframe {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

/* ========== Install Prompt Modal ========== */
#install-prompt-modal .modal-body {
  color: #000;
}

#install-prompt-modal .modal-body p {
  color: #000;
}

#install-prompt-modal .modal-header h3 {
  color: #000;
}

.modal-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--light-bg);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-secondary {
  background: var(--light-bg);
  color: var(--text-color);
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--border-color);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
  }

  header .header-right {
    width: 100%;
    justify-content: space-between;
  }

  nav.tabs button {
    padding: 0.75rem 0.5rem;
    font-size: 0.9rem;
  }

  .receipts-list.months-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .upload-area {
    margin: 1rem;
  }

  #auth-screen h2 {
    font-size: 1.8rem;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1.2rem;
  }

  header .user-info {
    font-size: 0.8rem;
  }

  #auth-screen h2 {
    font-size: 1.5rem;
  }

  #auth-screen p {
    font-size: 1rem;
  }

  .upload-area {
    padding: 1.5rem 0.75rem;
    width: calc(100% - 1.5rem);
    max-width: 100%;
  }

  .upload-area .icon {
    font-size: 2rem;
  }

  .receipts-list.months-grid {
    grid-template-columns: 1fr;
  }

  /* Prevent horizontal overflow on very small screens */
  .container, main, .main-content {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .receipt-item {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  table {
    font-size: 0.75rem;
  }

  .modal-content {
    max-width: 95vw;
  }
}

/* ========== Dark Mode Support ========== */
@media (prefers-color-scheme: dark) {
  :root {
    --light-bg: #34495e;
    --text-color: #ecf0f1;
  }

  html, body {
    background-color: #2c3e50;
    color: var(--text-color);
  }

  .upload-area {
    background: #34495e;
  }

  .receipt-item {
    background: #34495e;
    color: var(--text-color);
  }

  .receipt-item.file .file-name {
    color: var(--text-color);
  }

  nav.tabs {
    background: #34495e;
    border-bottom-color: #1c2833;
  }

  nav.tabs button.active {
    background: #1c2833;
  }

  .status-message.success {
    background: rgba(39, 174, 96, 0.2);
    color: #90ee90;
  }

  .status-message.error {
    background: rgba(231, 76, 60, 0.2);
    color: #ff6b6b;
  }

  .status-message.info {
    background: rgba(52, 152, 219, 0.2);
    color: #5dade2;
  }
}
