:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --fg: #1a1d23;
  --fg-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --warning-bg: #fef3c7;
  --warning-fg: #92400e;
  --warning-border: #fbbf24;
  --error: #c0392b;
  --success: #16a34a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  background: #f1f3f5;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ---------- Test banner ---------- */
.test-banner {
  background: var(--warning-bg);
  color: var(--warning-fg);
  border-bottom: 2px solid var(--warning-border);
  padding: 10px 16px;
  text-align: center;
  font-size: 14px;
}
.test-banner.hidden { display: none; }

/* ---------- Auth page ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.auth-card {
  background: var(--bg-elevated);
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  padding: 48px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}
.auth-card .brand .logo {
  font-size: 56px;
  margin-bottom: 12px;
}
.auth-card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 600;
}
.auth-card .subtitle {
  margin: 0 0 32px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.5;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 12px 20px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.btn-google:hover {
  background: #f9fafb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  text-decoration: none;
}

.hint {
  margin: 24px 0 0;
  color: var(--fg-muted);
  font-size: 12px;
}

/* ---------- App header (post-login) ---------- */
.app-header {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.app-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header .brand .logo { font-size: 24px; }
.app-header .brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.app-header nav {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-info {
  color: var(--fg-muted);
  font-size: 14px;
}
.user-info .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
  text-transform: uppercase;
}
.user-info .badge.admin  { background: #ede9fe; color: #6d28d9; }
.user-info .badge.member { background: #dbeafe; color: #1e40af; }

.btn-logout {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 13px;
  text-decoration: none;
}
.btn-logout:hover { background: #f9fafb; text-decoration: none; }

/* ---------- Container ---------- */
.container {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 20px;
}

.welcome h2 {
  margin: 0 0 12px;
  font-size: 22px;
}
.welcome > p {
  color: var(--fg-muted);
  margin: 0 0 24px;
}

.phase-status {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.phase-status h3 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--success);
}
.phase-status ul {
  margin: 0;
  padding-left: 20px;
  color: var(--fg-muted);
  line-height: 1.8;
}

.session-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
}
.session-card h3 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--fg-muted);
  letter-spacing: 0.04em;
}
.session-card table {
  width: 100%;
  border-collapse: collapse;
}
.session-card td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.session-card td:first-child {
  color: var(--fg-muted);
  width: 140px;
}
.session-card td:last-child {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.session-card tr:last-child td { border-bottom: none; }
.session-card .muted { color: var(--fg-muted); font-style: italic; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .app-header { padding: 10px 14px; }
  .container { padding: 0 14px; margin: 20px auto; }
  .auth-card { padding: 36px 24px; }
  .session-card td:first-child { width: 100px; }
}
/* ============================================ */
/* Phase 2: Receipts list, upload, detail       */
/* ============================================ */

.brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}
.brand-link:hover { text-decoration: none; }

.nav-link {
  color: var(--fg-muted);
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
}
.nav-link:hover { background: #f3f4f6; text-decoration: none; }
.nav-link.active { color: var(--accent); background: #eff6ff; }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 22px; }

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }
.btn-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
}
.btn-link:hover { color: var(--accent); text-decoration: none; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--fg-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

/* ---------- Receipt list ---------- */
.receipt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.receipt-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.receipt-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
  text-decoration: none;
}
.receipt-card-icon {
  font-size: 24px;
  flex-shrink: 0;
}
.receipt-card-body { flex: 1; min-width: 0; }
.receipt-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.receipt-card-vendor {
  font-weight: 500;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.receipt-card-amount {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.receipt-card-meta {
  display: flex;
  gap: 6px;
  color: var(--fg-muted);
  font-size: 12px;
  flex-wrap: wrap;
}
.owner-pill {
  background: #f1f5f9;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
}

.status-chip {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.status-DRAFT     { background: #f1f5f9; color: #475569; }
.status-WITH_BOSS { background: #fef3c7; color: #92400e; }
.status-APPROVED  { background: #d1fae5; color: #065f46; }
.status-REJECTED  { background: #fee2e2; color: #991b1b; }
.status-SUBMITTED { background: #dbeafe; color: #1e40af; }
.status-REFUNDED  { background: #ede9fe; color: #5b21b6; }
.status-WITHDRAWN { background: #f3f4f6; color: #6b7280; }

.loading, .empty {
  padding: 40px;
  text-align: center;
  color: var(--fg-muted);
}
.hidden { display: none !important; }

/* ---------- Upload form ---------- */
.form {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 720px;
  margin: 0 auto;
}

.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 20px;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent);
  background: #f0f7ff;
}
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop-zone-icon { font-size: 36px; margin-bottom: 8px; }
.drop-zone-text { margin: 0 0 4px; font-size: 15px; font-weight: 500; }
.drop-zone-hint { margin: 0; color: var(--fg-muted); font-size: 12px; }

.file-preview {
  margin-top: 12px;
  padding: 12px;
  background: #f9fafb;
  border-radius: 8px;
}
.file-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.file-preview-name {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-preview-size { color: var(--fg-muted); font-size: 12px; font-family: "SF Mono", Menlo, monospace; }
.file-preview-clear {
  background: transparent;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--error);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--fg-muted);
  font-weight: 500;
}
.form-grid label.full-width { grid-column: 1 / -1; }
.form-grid label > span { margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea {
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--fg);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.form-grid textarea { resize: vertical; min-height: 60px; }

.warning {
  padding: 10px 14px;
  background: var(--warning-bg);
  color: var(--warning-fg);
  border: 1px solid var(--warning-border);
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}
.error-msg {
  padding: 10px 14px;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .receipt-card-top { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ---------- Detail page ---------- */
.receipt-detail {
  max-width: 880px;
  margin: 0 auto;
}
.detail-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.detail-vendor { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.detail-amount { font-size: 24px; font-weight: 700; color: var(--accent); font-family: "SF Mono", Menlo, monospace; }

.detail-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
  font-size: 13px;
}
.detail-meta > div { display: flex; flex-direction: column; }
.detail-meta > div.full { grid-column: 1 / -1; }
.detail-meta span { color: var(--fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.detail-meta strong { font-size: 14px; font-weight: 500; word-break: break-word; }

.detail-file {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fafafa;
}
.detail-image { width: 100%; height: auto; display: block; }
.detail-iframe { width: 100%; height: 600px; border: 0; display: block; }

.detail-actions {
  display: flex;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
  .detail-meta { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; }
}

/* ---------- Print ---------- */
@media print {
  .app-header, .page-header, .detail-actions, .tabs, .form-actions,
  .nav-link, .btn-link, #test-banner { display: none !important; }
  body { background: white; }
  .container { margin: 0; max-width: 100%; padding: 0; }
  .receipt-detail, .detail-card, .form { box-shadow: none; border: none; padding: 0; }
  .detail-iframe { height: auto; min-height: 800px; }
  .detail-image { max-height: 90vh; }
  .status-chip { border: 1px solid #000; }
}
