/**
 * ActuallyVietnamese - App Styles
 * 
 * Light mode default with Material You CSS.
 */

/* ============================================
   Material Symbols Font
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200');

.material-symbols-rounded,
.md-icon {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings:
    'FILL' 0,
    'wght' 400,
    'GRAD' 0,
    'opsz' 24;
}

/* ============================================
   CSS Variables - Light Mode
   ============================================ */
:root {
  /* Override Material You for light mode */
  --md-sys-color-primary: #4f46e5;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #e0e7ff;
  --md-sys-color-on-primary-container: #1e1b4b;
  --md-sys-color-background: #ffffff;
  --md-sys-color-on-background: #1f2937;
  --md-sys-color-surface: #ffffff;
  --md-sys-color-on-surface: #1f2937;
  --md-sys-color-surface-variant: #f3f4f6;
  --md-sys-color-on-surface-variant: #4b5563;
  --md-sys-color-outline: #d1d5db;
  --md-sys-color-outline-variant: #e5e7eb;
  
  /* App-specific colors */
  --app-success: #10b981;
  --app-error: #ef4444;
  --app-warning: #f59e0b;
  --app-info: #3b82f6;
  
  /* Spacing */
  --app-spacing-xs: 0.25rem;
  --app-spacing-sm: 0.5rem;
  --app-spacing-md: 1rem;
  --app-spacing-lg: 1.5rem;
  --app-spacing-xl: 2rem;
  
  /* Layout */
  --app-max-width: 1200px;
  --app-header-height: 64px;
  --app-nav-height: 80px;
}

/* ============================================
   Layout
   ============================================ */
body {
  font-family: 'Roboto', system-ui, -apple-system, sans-serif;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  line-height: 1.5;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-container {
  flex: 1;
  max-width: var(--app-max-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--app-spacing-md);
  padding-bottom: calc(var(--app-nav-height) + var(--app-spacing-md));
}

.view {
  display: block;
}

.view.hidden {
  display: none;
}

/* ============================================
   Top App Bar
   ============================================ */
.md-top-app-bar {
  height: var(--app-header-height);
  padding: 0 var(--app-spacing-md);
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  background-color: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  position: sticky;
  top: 0;
  z-index: 100;
}

.md-top-app-bar-title {
  font-size: 1.25rem;
  font-weight: 500;
  flex: 1;
}

.md-top-app-bar-actions {
  display: flex;
  gap: var(--app-spacing-xs);
}

/* ============================================
   Status Bar
   ============================================ */
#status-bar {
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  background-color: var(--md-sys-color-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-lg);
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-xs);
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

.status-item .material-symbols-rounded {
  font-size: 18px;
}

.status-item.connected {
  color: var(--app-success);
}

.status-item.disconnected {
  color: var(--app-error);
}

.status-text {
  font-weight: 500;
}

/* ============================================
   Settings Form
   ============================================ */
.settings-container {
  max-width: 800px;
  margin: 0 auto;
  padding-bottom: calc(var(--app-nav-height) + var(--app-spacing-xl));
}

.fetch-container {
  padding-bottom: calc(var(--app-nav-height) + var(--app-spacing-xl));
}

.settings-section {
  margin-bottom: var(--app-spacing-xl);
  padding: var(--app-spacing-lg);
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
}

.settings-section h3 {
  margin-top: 0;
  margin-bottom: var(--app-spacing-sm);
}

.settings-help {
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: var(--app-spacing-md);
}

.settings-help a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

.settings-help a:hover {
  text-decoration: underline;
}

.md-text-field {
  margin-bottom: var(--app-spacing-md);
  width: 100%;
  max-width: 400px;
}

.md-text-field input {
  width: 100%;
}

.settings-actions {
  display: flex;
  gap: var(--app-spacing-sm);
  margin-top: var(--app-spacing-lg);
  padding-top: var(--app-spacing-lg);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.account-mapping {
  margin-bottom: var(--app-spacing-md);
}

.account-mapping label {
  display: block;
  margin-bottom: var(--app-spacing-xs);
}

.mapping-row {
  display: flex;
  gap: var(--app-spacing-sm);
  align-items: flex-start;
}

.mapping-row .md-text-field {
  flex: 1;
  margin-bottom: 0;
}

.account-select {
  padding: 12px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 4px;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  min-width: 200px;
}

#connection-status {
  margin-top: var(--app-spacing-sm);
  font-size: 0.875rem;
}

#connection-status .success {
  color: var(--app-success);
}

#connection-status .error {
  color: var(--app-error);
}

/* ============================================
   Date Selector
   ============================================ */
.date-selector {
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: var(--app-spacing-lg);
  margin-bottom: var(--app-spacing-lg);
}

.date-selector h3 {
  margin-top: 0;
  margin-bottom: var(--app-spacing-md);
}

.preset-buttons {
  display: flex;
  gap: var(--app-spacing-sm);
  margin-bottom: var(--app-spacing-md);
  flex-wrap: wrap;
}

.preset-buttons .md-chip {
  cursor: pointer;
}

.date-inputs {
  display: flex;
  gap: var(--app-spacing-md);
  margin-bottom: var(--app-spacing-md);
  flex-wrap: wrap;
}

.date-field {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}

.date-actions {
  display: flex;
  gap: var(--app-spacing-sm);
  flex-wrap: wrap;
}

/* ============================================
   Transaction List
   ============================================ */
.transaction-list {
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  overflow: hidden;
}

.transaction-header {
  padding: var(--app-spacing-lg);
  background-color: var(--md-sys-color-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.transaction-header h3 {
  margin: 0 0 var(--app-spacing-xs) 0;
}

.transaction-header p {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
}

.transaction-table-wrapper {
  overflow-x: auto;
}

.transaction-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.transaction-table th {
  text-align: left;
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  background-color: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  white-space: nowrap;
}

.transaction-table td {
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  vertical-align: middle;
}

.transaction-table tr:hover {
  background-color: var(--md-sys-color-surface-variant);
}

.transaction-table .selection-column {
  width: 1%;
  padding-right: 0;
}

.transaction-table .selection-column input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
}

.transaction-table .selection-column input:disabled {
  cursor: not-allowed;
}

.unhandled-email-list .transaction-table td:nth-child(2),
.unhandled-email-list .transaction-table td:nth-child(3),
.unhandled-email-list .transaction-table td:nth-child(4) {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

.account-badge.hsbc {
  background-color: #db00111a;
  color: #db0011;
}

.account-badge.cake {
  background-color: #ed44981a;
  color: #ed4498;
}

.account-badge.cake-savings {
  background-color: #ed44981a;
  color: #ed4498;
}

.account-badge.vietinbank {
  background-color: #0458941a;
  color: #045894;
}

.account-badge.momo {
  background-color: #b733831a;
  color: #b73383;
}

.account-badge.transfer-arrow {
  background-color: transparent;
  color: var(--md-sys-color-on-surface-variant);
  padding: 2px 4px;
  font-weight: 400;
}

.amount {
  font-weight: 500;
  white-space: nowrap;
}

.amount.positive {
  color: var(--app-success);
}

.amount.negative {
  color: var(--app-error);
}

/* General positive/negative color classes for preview tables */
.positive {
  color: var(--app-success);
}

.negative {
  color: var(--app-error);
}

.status {
  font-size: 0.75rem;
  font-weight: 500;
}

.status.pending {
  color: var(--md-sys-color-on-surface-variant);
}

.status.success {
  color: var(--app-success);
}

.status.error {
  color: var(--app-error);
}

.transaction-actions {
  display: flex;
  gap: var(--app-spacing-sm);
  padding: var(--app-spacing-lg);
  background-color: var(--md-sys-color-surface-variant);
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.import-summary {
  padding: var(--app-spacing-md);
  display: flex;
  gap: var(--app-spacing-md);
}

.import-summary .success {
  color: var(--app-success);
  font-weight: 500;
}

.import-summary .error {
  color: var(--app-error);
  font-weight: 500;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--app-spacing-xl);
  color: var(--md-sys-color-on-surface-variant);
}

.empty-state .material-symbols-rounded {
  color: var(--md-sys-color-outline);
  margin-bottom: var(--app-spacing-md);
}

/* ============================================
   Snackbar
   ============================================ */
.md-snackbar {
  position: fixed;
  bottom: calc(var(--app-nav-height) + var(--app-spacing-md));
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: var(--app-spacing-md);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  max-width: 90vw;
}

.md-snackbar.error {
  background-color: var(--app-error);
  color: white;
}

.md-snackbar.success {
  background-color: var(--app-success);
  color: white;
}

.md-snackbar.update {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.md-snackbar-action {
  background: none;
  border: none;
  color: inherit;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  text-transform: uppercase;
  font-size: 0.875rem;
}

.md-snackbar-action.secondary {
  opacity: 0.8;
}

/* ============================================
   Spinner
   ============================================ */
.md-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Navigation
   ============================================ */
.md-nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--md-sys-color-surface);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  height: var(--app-nav-height);
  display: flex;
  justify-content: center;
  gap: var(--app-spacing-xl);
  z-index: 100;
}

.md-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  font-size: 0.75rem;
  min-width: 80px;
  transition: color 0.2s;
}

.md-nav-item:hover,
.md-nav-item.active {
  color: var(--md-sys-color-primary);
}

.md-nav-item-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
}

.md-nav-item .material-symbols-rounded {
  font-size: 24px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .app-container {
    padding: var(--app-spacing-sm);
  }
  
  .settings-section {
    padding: var(--app-spacing-md);
  }
  
  .mapping-row {
    flex-direction: column;
  }
  
  .account-select {
    width: 100%;
  }
  
  .date-inputs {
    flex-direction: column;
  }
  
  .transaction-actions {
    flex-direction: column;
  }
  
  .transaction-actions .md-btn {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================
   Utility Classes
   ============================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ============================================
   Email Modal
   ============================================ */
.email-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--app-spacing-md);
}

.email-modal.hidden {
  display: none;
}

.email-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.email-modal-content {
  position: relative;
  background-color: var(--md-sys-color-surface);
  border-radius: 16px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.email-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--app-spacing-lg);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface-variant);
}

.email-modal-title {
  flex: 1;
  min-width: 0;
  margin-right: var(--app-spacing-md);
}

.email-modal-title h3 {
  margin: 0 0 var(--app-spacing-xs) 0;
  font-size: 1.125rem;
  font-weight: 500;
  word-break: break-word;
}

.email-modal-title p {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem;
}

.email-modal-actions {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
}

.email-modal-body {
  flex: 1;
  overflow: hidden;
  background-color: var(--md-sys-color-background);
}

#email-modal-iframe {
  width: 100%;
  height: 60vh;
  border: none;
  background-color: white;
}

/* ============================================
   Import Preview
   ============================================ */
.import-preview {
  padding: var(--app-spacing-lg);
  background-color: var(--md-sys-color-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.preview-table-wrapper {
  overflow-x: auto;
}

.import-preview h4 {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  margin: 0 0 var(--app-spacing-md) 0;
  color: var(--md-sys-color-primary);
}

.import-preview h4 .material-symbols-rounded {
  font-size: 20px;
}

.import-preview.warning {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  padding: var(--app-spacing-md);
  background-color: #fef3c7;
  color: #92400e;
  border-radius: 8px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-bottom: var(--app-spacing-md);
}

.preview-table th,
.preview-table td {
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  text-align: left;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.preview-table th {
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  background-color: var(--md-sys-color-surface);
}

.preview-table td {
  background-color: var(--md-sys-color-surface);
}

.preview-table tfoot td {
  border-top: 2px solid var(--md-sys-color-outline);
  border-bottom: none;
  background-color: var(--md-sys-color-surface-variant);
}

.preview-table .numeric {
  text-align: right;
  font-family: 'Roboto Mono', monospace;
}

.preview-note {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-xs);
  margin: 0;
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Loading state for preview */
.import-preview.loading .preview-loading-text {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  margin: 0 0 var(--app-spacing-md) 0;
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Error banner for preview */
.preview-error-banner {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  background-color: #fef2f2;
  color: #991b1b;
  border-radius: 8px;
  margin-bottom: var(--app-spacing-md);
  font-size: 0.875rem;
}

.preview-error-banner .material-symbols-rounded {
  font-size: 20px;
}

/* ============================================
   Import Results
   ============================================ */
.import-results {
  padding: var(--app-spacing-lg);
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin-top: var(--app-spacing-md);
  border-radius: 0 0 12px 12px;
}

.import-results h4 {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-sm);
  margin: 0 0 var(--app-spacing-sm) 0;
  color: #065f46;
}

.import-results h4 .material-symbols-rounded {
  font-size: 20px;
}

.import-results h5 {
  margin: var(--app-spacing-md) 0 var(--app-spacing-sm) 0;
  color: var(--md-sys-color-on-surface-variant);
}

.results-summary {
  margin: 0 0 var(--app-spacing-md) 0;
  font-size: 1rem;
  color: #065f46;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-bottom: var(--app-spacing-md);
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  overflow: hidden;
}

.results-table th,
.results-table td {
  padding: var(--app-spacing-sm) var(--app-spacing-md);
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.results-table th {
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  background-color: rgba(255, 255, 255, 0.9);
}

.results-table td {
  background-color: rgba(255, 255, 255, 0.5);
}

.results-table .numeric {
  text-align: right;
  font-family: 'Roboto Mono', monospace;
}

.results-info {
  padding: var(--app-spacing-md);
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

.results-info p {
  display: flex;
  align-items: center;
  gap: var(--app-spacing-xs);
  margin: 0 0 var(--app-spacing-xs) 0;
  color: var(--md-sys-color-on-surface-variant);
}

.results-info ul {
  margin: 0;
  padding-left: var(--app-spacing-lg);
  color: var(--md-sys-color-on-surface-variant);
}

.results-info li {
  margin-bottom: 2px;
}

/* ============================================
   Transaction Table Enhancements
   ============================================ */
.transaction-row {
  transition: background-color 0.15s ease;
}

.transaction-row:hover {
  background-color: var(--md-sys-color-surface-variant) !important;
}

.transaction-row:not(.selected) {
  opacity: 0.55;
}

.view-email-btn {
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.transaction-row:hover .view-email-btn,
.view-email-btn:hover {
  opacity: 1;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
  .email-modal-content {
    max-height: 95vh;
    border-radius: 12px;
  }

  #email-modal-iframe {
    height: 50vh;
  }

  .preview-table,
  .results-table {
    font-size: 0.8125rem;
  }

  .preview-table th,
  .preview-table td,
  .results-table th,
  .results-table td {
    padding: var(--app-spacing-xs) var(--app-spacing-sm);
  }

  .import-preview,
  .import-results {
    padding: var(--app-spacing-md);
  }
}

/* ============================================
   Dark Mode Overrides
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    /* Override Material You dark mode with vibrant indigo */
    --md-sys-color-primary: #818cf8;
    --md-sys-color-on-primary: #1e1b4b;
    --md-sys-color-primary-container: #3730a3;
    --md-sys-color-on-primary-container: #e0e7ff;
  }
}
