@import url('https://rsms.me/inter/inter.css');

:root {
  --mysa-green: #1F7A3A;
  --mysa-green-hover: #196530;
  --mysa-green-light: #E8F4ED;
  --mysa-green-tint: rgba(31, 122, 58, 0.08);

  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F5F5F1;
  --surface-3: #EFEFE9;
  --border: #E5E5DF;
  --border-strong: #D4D4CC;
  --text: #1A1A17;
  --text-muted: #6B6B66;
  --text-subtle: #9A9A93;

  --danger: #B91C1C;
  --danger-bg: #FEF2F2;
  --warning: #B45309;
  --warning-bg: #FEF8E7;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-feature: 'cv11', 'ss01', 'ss03';

  --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
  --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-8: 2rem; --sp-10: 2.5rem;
  --sp-12: 3rem; --sp-16: 4rem;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 9999px;

  --sh-sm: 0 1px 2px rgba(20,20,15,.04), 0 1px 1px rgba(20,20,15,.02);
  --sh-md: 0 4px 12px rgba(20,20,15,.06), 0 1px 2px rgba(20,20,15,.03);
  --sh-lg: 0 12px 32px rgba(20,20,15,.08), 0 2px 6px rgba(20,20,15,.04);
  --sh-focus: 0 0 0 3px rgba(31,122,58,.18);

  --t-fast: 120ms cubic-bezier(.4,0,.2,1);
  --t-base: 180ms cubic-bezier(.4,0,.2,1);

  --content-max: 1280px;
  --content-narrow: 480px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F0F0E;
    --surface: #1A1A18;
    --surface-2: #232321;
    --surface-3: #2A2A27;
    --border: #2E2E2B;
    --border-strong: #3A3A37;
    --text: #F0F0EC;
    --text-muted: #A8A8A2;
    --text-subtle: #6B6B66;
    --mysa-green-light: rgba(31,122,58,.15);
    --mysa-green-tint: rgba(31,122,58,.12);
    --danger-bg: rgba(185,28,28,.1);
    --warning-bg: rgba(180,83,9,.12);
  }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-feature-settings: var(--font-feature);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

@supports (font-variation-settings: normal) { body { font-family: 'Inter var', var(--font-sans); } }

img { max-width: 100%; display: block; }

/* ---------- Top nav ---------- */
.topnav {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topnav-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-6);
  min-height: 56px;
}

.topnav-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.topnav-brand img { height: 28px; }

.topnav-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.topnav-label {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
}

.topnav-links {
  display: flex;
  gap: var(--sp-1);
  flex: 1;
  flex-wrap: wrap;
  margin-left: var(--sp-2);
}

.topnav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}

.topnav-link:hover { background: var(--surface-2); color: var(--text); }
.topnav-link.is-active { background: var(--mysa-green-tint); color: var(--mysa-green); }

.topnav-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-left: auto;
  flex-shrink: 0;
}

.topnav-username {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.topnav-mobile-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  cursor: pointer;
  color: var(--text);
}

@media (max-width: 880px) {
  .topnav-links { display: none; flex-direction: column; gap: 0; }
  .topnav-links.is-open {
    display: flex;
    position: absolute;
    top: 56px;
    left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--sp-3);
    box-shadow: var(--sh-md);
  }
  .topnav-mobile-toggle { display: inline-flex; }
  .topnav-divider, .topnav-label { display: none; }
}

/* ---------- Layout ---------- */
.shell { padding: var(--sp-8) var(--sp-6) var(--sp-12); }

.shell-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
  flex-wrap: wrap;
}

.page-header-text { min-width: 0; }

.eyebrow {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mysa-green);
  margin-bottom: var(--sp-2);
}

.h1 {
  font-size: clamp(1.5rem, 1.2rem + 1vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0;
}

.h2 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.lede {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: var(--sp-1) 0 0;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.8125rem; }
.mono { font-family: var(--font-mono); font-size: 0.875rem; }

/* ---------- Cards / KPI ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--sh-sm);
}

.card-tight { padding: var(--sp-4); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.kpi-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: var(--sp-2);
}

/* ---------- Two-column layout for dashboards ---------- */
.split-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--sp-4);
  align-items: start;
}

@media (max-width: 880px) {
  .split-2 { grid-template-columns: 1fr; }
}

/* ---------- List rows (recent items) ---------- */
.list-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  align-items: center;
}

.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-2); }

.list-row-primary { font-weight: 500; font-size: 0.9375rem; }
.list-row-meta { font-size: 0.8125rem; color: var(--text-muted); margin-top: 2px; }

.list-row-side { font-size: 0.8125rem; color: var(--text-subtle); white-space: nowrap; }

/* ---------- Forms / inputs ---------- */
.field { margin-bottom: var(--sp-4); }
.label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: var(--sp-2); color: var(--text); }

.input {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  -webkit-appearance: none; appearance: none;
}

.input::placeholder { color: var(--text-subtle); }
.input:hover { border-color: var(--text-subtle); }
.input:focus { outline: none; border-color: var(--mysa-green); box-shadow: var(--sh-focus); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--mysa-green); color: white; border-color: var(--mysa-green); }
.btn-primary:hover:not(:disabled) { background: var(--mysa-green-hover); border-color: var(--mysa-green-hover); }
.btn-primary:focus-visible { outline: none; box-shadow: var(--sh-focus); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--text-subtle); background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; padding: var(--sp-2) var(--sp-3); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-danger { background: var(--surface); color: var(--danger); border-color: rgba(185, 28, 28, 0.3); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }

.btn-sm { padding: var(--sp-2) var(--sp-3); font-size: 0.8125rem; }
.btn-block { width: 100%; }

/* ---------- Alerts ---------- */
.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: var(--sp-4);
  border: 1px solid transparent;
}

.alert-error { background: var(--danger-bg); border-color: rgba(185,28,28,.2); color: var(--danger); }
.alert-success { background: var(--mysa-green-light); border-color: rgba(31,122,58,.2); color: var(--mysa-green); }
.alert-warning { background: var(--warning-bg); border-color: rgba(180,83,9,.25); color: var(--warning); }

/* ---------- Login screen ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-6);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-8);
  box-shadow: var(--sh-md);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-6);
}

.auth-brand img { height: 40px; }

.auth-title {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 var(--sp-1);
}

.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0 0 var(--sp-6);
}

/* ---------- Spinner / loading ---------- */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-line { height: 14px; margin-bottom: var(--sp-2); }
.skeleton-line:last-child { width: 60%; }

/* ---------- Utilities ---------- */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

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

/* ============================================================
   Batch 2: list filters, data table, detail page, modal
   ============================================================ */

.filter-bar {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}

.filter-search { max-width: 320px; }

.chip-row { display: flex; gap: var(--sp-1); flex-wrap: wrap; }

.chip {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
}

.chip:hover { background: var(--surface-2); color: var(--text); }

.chip.is-active {
  background: var(--mysa-green-tint);
  color: var(--mysa-green);
  border-color: color-mix(in srgb, var(--mysa-green) 35%, transparent);
}

/* Table */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-sm);
}

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

.data-table thead th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.data-table tbody td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table tbody tr { cursor: pointer; transition: background var(--t-fast); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

.cell-primary { font-weight: 500; color: var(--text); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th.num { text-align: right; }

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge-success {
  background: var(--mysa-green-light);
  color: var(--mysa-green);
  border-color: color-mix(in srgb, var(--mysa-green) 25%, transparent);
}

.badge-info {
  background: rgba(59, 130, 246, 0.1);
  color: #2563EB;
  border-color: rgba(59, 130, 246, 0.25);
}

@media (prefers-color-scheme: dark) {
  .badge-info { background: rgba(96, 165, 250, 0.15); color: #60A5FA; border-color: rgba(96, 165, 250, 0.3); }
}

.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(180, 83, 9, 0.25); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--sp-4);
  padding: 0 var(--sp-2);
}

.pagination-controls { display: flex; align-items: center; gap: var(--sp-3); }

/* Detail grid */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--sp-6);
  align-items: start;
}

@media (max-width: 980px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-side { position: sticky; top: 80px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: var(--sp-4);
  padding: var(--sp-1) 0;
}
.back-link:hover { color: var(--text); }

/* File grid */
.file-grid {
  display: grid;
  gap: var(--sp-2);
}

.file-tile {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--t-fast);
}

.file-tile:hover { border-color: var(--text-subtle); }

.file-tile-icon { font-size: 1.5rem; flex-shrink: 0; line-height: 1; }
.file-tile-meta { flex: 1; min-width: 0; }
.file-tile-name { font-size: 0.9375rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-tile-size { font-size: 0.8125rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Audit list */
.audit-list { display: grid; gap: var(--sp-3); }

.audit-row {
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 0.875rem;
}

.audit-row-action { font-weight: 500; font-family: var(--font-mono); font-size: 0.8125rem; color: var(--mysa-green); margin-bottom: 2px; }
.audit-row-meta { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: var(--sp-1); }
.audit-row-details {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  margin: var(--sp-2) 0;
  overflow-x: auto;
  word-break: break-word;
  white-space: pre-wrap;
}
.audit-row-time { font-size: 0.75rem; color: var(--text-subtle); }

/* Share row */
.share-list { display: grid; gap: var(--sp-2); }

.share-row {
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: var(--sp-4);
  animation: fade-in 120ms ease-out;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 1100px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.modal-title {
  font-weight: 500;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body {
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  padding: var(--sp-4);
}

.modal-img { max-width: 100%; max-height: 80vh; display: block; }
.modal-video { max-width: 100%; max-height: 80vh; }
.modal-iframe { width: 100%; height: 80vh; border: none; background: var(--surface); }
