/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --primary:        #1e3a6e;
  --primary-light:  #2d5fa8;
  --primary-bg:     #e8f0fb;
  --surface:        #ffffff;
  --background:     #f0f4f8;
  --border:         #dde3ea;
  --text:           #1a202c;
  --text-muted:     #64748b;
  --radius:         8px;
  --shadow:         0 1px 4px rgba(0,0,0,.08);
  --shadow-md:      0 4px 12px rgba(0,0,0,.10);

  /* Status colours */
  --submitted-bg:    #dcfce7; --submitted-text:    #15803d;
  --failed-bg:       #fee2e2; --failed-text:       #dc2626;
  --pending-bg:      #fef3c7; --pending-text:      #b45309;
  --processing-bg:   #e0f2fe; --processing-text:   #0369a1;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--background);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.container { max-width: 60%; min-width: 0; margin: 0 auto; padding: 0 1.25rem; }

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 52px;
}
.brand {
  display: flex; align-items: center; gap: .6rem;
  text-decoration: none; color: #fff;
  padding: .6rem 0;
  flex-shrink: 0;
}
.brand-logo {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.brand-logo svg { width: 36px; height: 36px; }
.brand-name  { font-size: 1rem; font-weight: 700; letter-spacing: .02em; }
.brand-powered { font-size: .72rem; opacity: .65; margin-top: .05rem; }

/* Navigation links */
.main-nav {
  display: flex;
  align-items: center;
  gap: .15rem;
  margin-left: .5rem;
}
.nav-link {
  color: rgba(255,255,255,.7);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  padding: .4rem .75rem;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.18); color: #fff; }

/* User menu (right side) */
.user-menu {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
}
.user-name {
  font-size: .82rem;
  font-weight: 600;
  opacity: .9;
}
.nav-logout {
  font-size: .78rem;
  opacity: .65;
}
.nav-logout:hover { opacity: 1; }

/* Page indicator pill (e.g. store name on upload page) */
.page-indicator {
  font-size: .75rem; font-weight: 600;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px;
  padding: .2rem .65rem;
  white-space: nowrap;
}

/* ── Main content ────────────────────────────────────────────────────────── */
main { flex: 1; padding: 2rem 0 3rem; }

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 1.1rem;
}

/* ── Upload zone ─────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  position: relative;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}
.upload-zone input[type="file"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.upload-icon { margin-bottom: .75rem; color: var(--text-muted); }
.upload-icon svg { width: 40px; height: 40px; }
.upload-label   { font-size: 1rem; font-weight: 600; color: var(--primary); margin-bottom: .3rem; }
.upload-hint    { font-size: .85rem; color: var(--text-muted); }

/* ── File list ───────────────────────────────────────────────────────────── */
.file-list { margin-top: 1rem; display: flex; flex-direction: column; gap: .4rem; }
.file-item {
  display: flex; align-items: center; gap: .5rem;
  background: var(--primary-bg);
  border: 1px solid #c7d8f5;
  border-radius: 6px;
  padding: .4rem .75rem;
  font-size: .85rem;
}
.file-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--primary); }
.file-name     { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-remove   { background: none; border: none; cursor: pointer; color: var(--text-muted);
                  padding: 0; line-height: 1; font-size: 1.1rem; }
.file-remove:hover { color: var(--failed-text); }

/* ── Upload button ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.4rem;
  border-radius: 6px; border: none; cursor: pointer;
  font-size: .9rem; font-weight: 600; transition: opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); }
.btn-row { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }

/* ── Progress / messages ─────────────────────────────────────────────────── */
.messages { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.message {
  border-radius: 6px; padding: .65rem 1rem; font-size: .875rem;
  display: flex; align-items: flex-start; gap: .5rem;
}
.message svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: .1rem; }
.msg-success { background: var(--submitted-bg); color: var(--submitted-text); }
.msg-error   { background: var(--failed-bg);    color: var(--failed-text); }
.msg-warning { background: var(--pending-bg);   color: var(--pending-text); }
.msg-info    { background: var(--processing-bg);color: var(--processing-text); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(0,0,0,.15);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}

/* ── Status badge ────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: .2rem .6rem;
  border-radius: 20px; font-size: .75rem; font-weight: 600;
  text-transform: capitalize; white-space: nowrap;
}
.badge-submitted         { background: var(--submitted-bg);  color: var(--submitted-text); }
.badge-failed            { background: var(--failed-bg);     color: var(--failed-text); }
.badge-pending_pair      { background: var(--pending-bg);    color: var(--pending-text); }
.badge-processing        { background: var(--processing-bg); color: var(--processing-text); }
.badge-validated         { background: #dcfce7;              color: #166534; }
.badge-validation_failed { background: var(--failed-bg);     color: var(--failed-text); }
.badge-validating        { background: var(--processing-bg); color: var(--processing-text); }
.badge-importing         { background: var(--processing-bg); color: var(--processing-text); }

/* ── History table ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left; padding: .6rem .75rem;
  background: var(--background); border-bottom: 2px solid var(--border);
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
}
td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
.td-date   { font-weight: 600; white-space: nowrap; }
.td-file   { color: var(--text-muted); font-size: .8rem; max-width: 200px;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-error  { color: var(--failed-text); font-size: .8rem; max-width: 260px;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 2rem; font-style: italic; }

/* ── Admin stats ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: .15rem; }

/* ── Store cards (dashboard) ─────────────────────────────────────────────── */
.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}
.store-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  transition: box-shadow .15s, border-color .15s;
  background: var(--background);
}
.store-card:hover { box-shadow: var(--shadow-md); border-color: var(--primary-light); }
.store-card-alert { border-left: 3px solid var(--failed-text); }
.store-card-name {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  line-height: 1.3;
}
.store-card-meta {
  font-size: .8rem;
  color: var(--text-muted);
  flex: 1;
}
.store-card-stats {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}
.store-card-upload {
  margin-top: .4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1rem;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: .875rem;
  transition: background .15s;
}
.store-card-upload:hover { background: var(--primary-light); }
.store-card-manage {
  font-size: .75rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.store-card-manage:hover { color: var(--text); text-decoration: underline; }

/* ── Admin tables — wider columns ────────────────────────────────────────── */
.admin-table th:first-child,
.admin-table td:first-child { width: 15%; }
.admin-table .td-url  { font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
                         font-size: .78rem; color: var(--text-muted); word-break: break-all; }
.admin-table .td-note { max-width: none; white-space: normal; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-block;
  font-size: .85rem;
  color: var(--primary-light);
  text-decoration: none;
  margin-bottom: 1rem;
}
.back-link:hover { text-decoration: underline; }

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: .3rem;
  color: var(--text-muted);
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"] {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(45,95,168,.12);
}
.form-group input[readonly] {
  background: var(--background);
  color: var(--text-muted);
  cursor: default;
}
.field-hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .25rem;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
footer {
  background: var(--surface); border-top: 1px solid var(--border);
  text-align: center; padding: 1rem;
  font-size: .78rem; color: var(--text-muted);
}
footer a { color: var(--primary-light); text-decoration: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .container { max-width: 90%; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .header-inner { gap: .75rem; flex-wrap: wrap; }
  .main-nav { order: 3; width: 100%; padding-bottom: .5rem; }
  .page-indicator { display: none; }
  .card { padding: 1rem; }
  .upload-zone { padding: 1.5rem 1rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Upload page two-column layout ──────────────────────────────────────── */
.upload-top-grid {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  gap: 1.25rem;
  align-items: stretch;   /* both cards grow to match the taller one (calendar) */
  margin-bottom: 0;
}

/* Upload card fills its grid cell and distributes space internally */
.upload-top-grid .card:first-child {
  display: flex;
  flex-direction: column;
}
.upload-top-grid .card:first-child .file-list {
  flex: 1;
  min-height: 0;          /* allows flex child to shrink below content size */
  overflow-y: auto;
}
.upload-top-grid #messages {
  overflow-y: auto;       /* scroll messages instead of growing the card */
  max-height: 15rem;
}
@media (max-width: 780px) {
  .upload-top-grid { grid-template-columns: 1fr; }
}

/* Scrollable history table — prevents the page growing indefinitely */
.history-scroll {
  max-height: 440px;
  overflow-y: auto;
}
.history-scroll thead th {
  position: sticky;
  top: 0;
  background: var(--background);
  z-index: 1;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Calendar
   ══════════════════════════════════════════════════════════════════════════ */

.cal-status {
  font-size: .75rem; font-weight: 400;
  color: var(--text-muted); margin-left: .5rem;
}

/* Year navigation bar */
.cal-nav {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: .85rem;
}
.cal-year-label { font-size: 1rem; font-weight: 700; }
.cal-nav-btn {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  padding: .2rem .7rem; cursor: pointer; font-size: 1rem; line-height: 1.4;
  color: var(--text-muted); transition: background .15s;
}
.cal-nav-btn:hover { background: var(--background); color: var(--text); }

/* 4-column year grid */
.cal-year-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem 1rem;
}
@media (max-width: 680px) {
  .cal-year-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Individual month block */
.cal-month-name {
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); text-align: center;
  margin-bottom: .3rem;
}

/* Mini 7-column day grid */
.cal-mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.cal-mini-dow {
  text-align: center; font-size: .55rem; font-weight: 700;
  color: var(--border); padding: .1rem 0;
}
.cal-mini-day {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 2px; font-size: .62rem;
  cursor: default; user-select: none;
}

/* Shared day states (used by both .cal-day and .cal-mini-day) */
.cal-mini-day.submitted,
.cal-day.submitted    { background: var(--submitted-bg); color: var(--submitted-text); }
.cal-mini-day.missing,
.cal-day.missing      { background: var(--failed-bg);    color: var(--failed-text); }
.cal-mini-day.future,
.cal-day.future       { background: var(--background);   color: var(--text-muted); }
.cal-mini-day.before-start,
.cal-day.before-start { background: none; color: var(--border); }
.cal-mini-day.empty,
.cal-day.empty        { background: none; }
.cal-mini-day.today,
.cal-day.today        { box-shadow: 0 0 0 2px var(--primary); font-weight: 700; }

.cal-legend {
  display: flex; gap: 1.25rem; flex-wrap: wrap;
  margin-top: .85rem; padding-top: .75rem;
  border-top: 1px solid var(--border);
}
.leg-item {
  display: flex; align-items: center; gap: .35rem;
  font-size: .75rem; color: var(--text-muted);
}
.leg-item::before {
  content: ''; width: 12px; height: 12px;
  border-radius: 3px; display: inline-block; flex-shrink: 0;
}
.leg-submitted::before { background: var(--submitted-bg); border: 1px solid var(--submitted-text); }
.leg-missing::before   { background: var(--failed-bg);    border: 1px solid var(--failed-text); }
.leg-today::before     { background: transparent; box-shadow: 0 0 0 2px var(--primary); }
.leg-future::before    { background: var(--background);   border: 1px solid var(--border); }
