:root {
  --bg-primary: #f5f5f5;
  --bg-card: #fff;
  --bg-elevated: #f0f0f0;
  --border: #ddd;
  --border-light: #e8e8e8;
  --text-primary: #1a1a1a;
  --text-secondary: #333;
  --text-muted: #666;
  --text-dim: #888;
  --text-faint: #aaa;
  --text-ghost: #ccc;
  --accent: #e31837;
  --accent-dark: #b01230;
  --font-sans: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  background: linear-gradient(135deg, #fff 0%, #f5f5f5 100%);
  border-bottom: 2px solid var(--accent);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  display: flex;
  align-items: center;
}

.header-logo-img {
  height: 28px;
  width: auto;
}

.header-divider {
  width: 1px;
  height: 24px;
  background: var(--text-ghost);
}

.header-subtitle {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.header-stats {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
}

/* Container */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Labels */
.label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

/* Inputs */
.input-field {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  outline: none;
}

.input-field:focus {
  border-color: var(--text-ghost);
}

.input-field:user-invalid {
  border-color: var(--accent);
  background: rgba(227, 24, 55, 0.04);
}

.input-inline {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 4px 6px;
  color: var(--text-secondary);
  font-size: 13px;
  outline: none;
}

.input-inline:focus {
  border-color: var(--text-ghost);
}

.input-inline--date {
  font-family: var(--font-mono);
  width: 80px;
}

.input-inline--description {
  font-family: var(--font-sans);
  width: 100%;
}

.input-inline--amount {
  font-family: var(--font-mono);
  text-align: right;
  width: 85px;
  color: var(--text-primary);
}

select.input-field,
select.input-inline {
  cursor: pointer;
}

.select-category {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  cursor: pointer;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: linear-gradient(135deg, #f0f0f5 0%, var(--bg-card) 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 20px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
}

.btn-secondary:hover {
  border-color: var(--text-dim);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
  line-height: 1;
}

.btn-link:hover {
  color: var(--accent);
}

/* Details/Summary toggle */
details.employee-info > summary {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: var(--font-sans);
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
}

details.employee-info > summary::-webkit-details-marker {
  display: none;
}

details.employee-info > summary .summary-label {
  text-transform: uppercase;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1.5px;
}

details.employee-info > summary .summary-icon {
  color: var(--text-dim);
  font-size: 18px;
}

details.employee-info[open] > summary {
  border-radius: 8px 8px 0 0;
  margin-bottom: 0;
}

details.employee-info > .employee-info-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 20px;
}

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-card);
  transition: all 0.2s ease;
  margin-bottom: 24px;
}

.upload-zone:hover,
.upload-zone--active {
  border-color: var(--accent);
  background: rgba(227, 24, 55, 0.05);
}

.upload-zone-icon {
  font-size: 32px;
  margin-bottom: 8px;
  opacity: 0.6;
}

.upload-zone-text {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}

.upload-zone-hint {
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 4px;
}

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

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

/* Line items table */
.line-items-card {
  overflow: hidden;
  margin-bottom: 24px;
}

.table-header {
  display: grid;
  grid-template-columns: 44px 90px 1fr 130px 140px 100px 40px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 600;
}

.line-item-row {
  display: grid;
  grid-template-columns: 44px 90px 1fr 130px 140px 100px 40px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  align-items: center;
  font-size: 13px;
  min-width: 0;
}

.line-item-row > * {
  min-width: 0;
}

.line-item-row > form {
  display: contents;
}

.line-item-icon {
  font-size: 18px;
  text-align: center;
}

.line-item-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-width: 0;
  height: 36px;
  max-height: 36px;
}

.thumb-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  line-height: 0;
  overflow: hidden;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  position: relative;
}

.thumb-btn:hover {
  border-color: var(--text-dim);
}

.thumb-img {
  width: 36px;
  height: 36px;
  max-width: 36px;
  max-height: 36px;
  object-fit: cover;
  display: block;
}

/* Lightbox dialog */
.lightbox-dialog {
  border: none;
  background: transparent;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  position: fixed;
}

.lightbox-dialog:not([open]) {
  display: none;
}

.lightbox-dialog::backdrop {
  background: rgba(0, 0, 0, 0.85);
}

.lightbox-content {
  position: relative;
}

.lightbox-close {
  position: absolute;
  top: -32px;
  right: -4px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
  border-radius: 4px;
}

.lightbox-close:hover {
  background: rgba(0, 0, 0, 0.9);
}

.lightbox-img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
}

/* Header right cluster (stats + help) */
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Make the button_to form wrapper transparent to flex layout */
.header-new-report-form {
  display: contents;
}

/* Help button */
.help-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  letter-spacing: 0.3px;
}

.help-button:hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

.help-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* Help dialog */
.help-dialog {
  border: none;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 0;
  max-width: 640px;
  width: calc(100% - 32px);
  max-height: 85vh;
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.help-dialog:not([open]) {
  display: none;
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.help-dialog-content {
  padding: 28px 32px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.help-dialog-content h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.help-dialog-content h3 {
  margin: 24px 0 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.help-dialog-content p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.help-dialog-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.help-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.help-dialog-close:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* Miles field (Mileage/Tolls) */
.miles-field {
  display: none;
  align-items: center;
  gap: 4px;
}

.miles-field--visible {
  display: flex;
}

.input-inline--miles {
  width: 60px;
}

.miles-rate {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

.description-cell {
  min-width: 0;
}

.mileage-note {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

.add-row-btn {
  width: 100%;
  background: none;
  border: none;
  border-top: 1px dashed var(--border-light);
  padding: 8px;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
}

.add-row-btn:hover {
  color: var(--text-muted);
}

/* Category breakdown + totals */
.totals-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 16px;
  margin-bottom: 24px;
}

.category-breakdown {
  padding: 16px;
}

.category-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 12px;
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-chip {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-chip-icon {
  font-size: 14px;
}

.category-chip-name {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.category-chip-amount {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
}

.grand-total-card {
  background: linear-gradient(135deg, #fff0f2 0%, var(--bg-card) 100%);
  border: 1px solid #f0c0c8;
  border-radius: 8px;
  padding: 20px;
  text-align: right;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.grand-total-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #666;
  margin-bottom: 4px;
}

.grand-total-amount {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.grand-total-count {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Action buttons */
.action-buttons {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

/* Email fields */
.email-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.email-fields--three {
  grid-template-columns: 1fr 1fr auto;
}

.email-fields--three input[name*="year"] {
  width: 80px;
}

/* Expense statement preview table */
.preview-table-wrapper {
  overflow: hidden;
}

.preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-header-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 600;
}

.preview-header-note {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}

.preview-table th {
  padding: 8px 10px;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.preview-table th.text-left { text-align: left; }
.preview-table th.text-right { text-align: right; }

.preview-table td {
  padding: 6px 10px;
}

.preview-table tr {
  border-bottom: 1px solid var(--border-light);
}

.preview-table .totals-row {
  border-top: 2px solid var(--border);
  background: var(--bg-elevated);
}

.preview-table .totals-row td {
  padding: 8px 10px;
  font-weight: 600;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-ghost);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.3;
}

.empty-state-text {
  font-size: 14px;
  font-weight: 500;
}

.empty-state-hint {
  font-size: 12px;
  margin-top: 4px;
  color: var(--border);
}

/* Flash messages */
.flash {
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}

.flash--notice {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #22c55e;
}

.flash--error {
  background: rgba(227, 24, 55, 0.1);
  border: 1px solid rgba(227, 24, 55, 0.3);
  color: var(--accent);
}

/* Landing page */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.landing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.landing-logo {
  margin-bottom: 8px;
}

.landing-logo-img {
  height: 36px;
  width: auto;
}

.landing-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 32px;
}

.landing-form {
  text-align: left;
}

.landing-form .label {
  margin-bottom: 6px;
}

.landing-form .input-field {
  margin-bottom: 20px;
}

.landing-btn {
  width: 100%;
}

/* Not found page */
.not-found {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.not-found-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.not-found-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.not-found-text {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.not-found-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.not-found-link:hover {
  text-decoration: underline;
}

/* Spacing helpers */
.mb-0 { margin-bottom: 0; }
.mb-24 { margin-bottom: 24px; }

/* Responsive */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .email-fields {
    grid-template-columns: 1fr;
  }

  .totals-grid {
    grid-template-columns: 1fr;
  }

  .table-header,
  .line-item-row {
    grid-template-columns: 30px 70px 1fr 100px 80px 30px;
    font-size: 11px;
  }

  .header-right {
    gap: 10px;
  }

  .help-button {
    padding: 6px 10px;
  }

  .help-button > span:not(.help-button-icon) {
    display: none;
  }
}
