:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #6c707a;
  --line: #e2e0d8;
  --accent: #16181d;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --ok: #2c7a2c;
  --radius: 8px;
  --card-shadow: 0 4px 16px rgba(0,0,0,.06);
  --toast-shadow: 0 6px 24px rgba(0,0,0,.2);
  --photo-del-bg: rgba(0,0,0,.6);
  --backdrop: rgba(0,0,0,.4);
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #1a1d23;
  --ink: #ececeb;
  --muted: #9aa0a8;
  --line: #2a2d33;
  --accent: #ececeb;
  --accent-ink: #0f1115;
  --danger: #e57373;
  --ok: #6abf6a;
  --card-shadow: 0 4px 16px rgba(0,0,0,.5);
  --toast-shadow: 0 6px 24px rgba(0,0,0,.6);
  --photo-del-bg: rgba(0,0,0,.75);
  --backdrop: rgba(0,0,0,.65);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0f1115;
    --surface: #1a1d23;
    --ink: #ececeb;
    --muted: #9aa0a8;
    --line: #2a2d33;
    --accent: #ececeb;
    --accent-ink: #0f1115;
    --danger: #e57373;
    --ok: #6abf6a;
    --card-shadow: 0 4px 16px rgba(0,0,0,.5);
    --toast-shadow: 0 6px 24px rgba(0,0,0,.6);
    --photo-del-bg: rgba(0,0,0,.75);
    --backdrop: rgba(0,0,0,.65);
  }
}
* { box-sizing: border-box; }
/* HTML `hidden` would otherwise be defeated by the `display: flex/grid`
   rules below — admin.js toggles `hidden` to switch tabs and auth state. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 18px; } h2 { font-size: 18px; } h3 { font-size: 14px; }
button { font: inherit; cursor: pointer; }

/* Login */
.login-section { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-form { background: var(--surface); padding: 28px; border-radius: var(--radius);
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--card-shadow); }
.login-form h1 { text-align: center; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; font: inherit;
  background: var(--surface); color: var(--ink); }
.login-form button { padding: 10px; background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 6px; font-weight: 600; }

/* Dashboard chrome */
.dash-header { display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.dash-header h1 { margin: 0; }
.dash-nav { display: flex; gap: 4px; flex: 1; }
.tab-btn { background: transparent; border: none; padding: 8px 14px; border-radius: 6px;
  color: var(--muted); }
.tab-btn:hover { background: var(--bg); }
.tab-btn.is-active { background: var(--accent); color: var(--accent-ink); }
.dash-user { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.dash-user button { background: transparent; border: 1px solid var(--line); padding: 6px 12px;
  border-radius: 6px; color: var(--ink); }

.lang-toggle,
.theme-toggle { background: transparent; border: 1px solid var(--line); padding: 4px 10px;
  border-radius: 4px; color: var(--muted); font-size: 12px; font-weight: 700;
  letter-spacing: .05em; cursor: pointer; min-width: 36px; }
.lang-toggle:hover,
.theme-toggle:hover { color: var(--ink); border-color: var(--ink); }
.login-toggles { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.dash-main { padding: 24px; max-width: 1200px; margin: 0 auto; }

/* Tab panels */
.tab-panel { display: flex; flex-direction: column; gap: 20px; }
.panel-toolbar { display: flex; align-items: center; justify-content: space-between; }

/* Buttons */
.btn-primary { background: var(--accent); color: var(--accent-ink); border: none;
  padding: 8px 14px; border-radius: 6px; font-weight: 600; }
.btn-row { display: flex; gap: 6px; }
.btn-row button { background: transparent; border: 1px solid var(--line); padding: 4px 10px;
  border-radius: 4px; font-size: 13px; }
.btn-row .danger { color: var(--danger); border-color: var(--danger); }

/* Stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat-card { background: var(--surface); padding: 14px 18px; border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-num { font-size: 28px; font-weight: 700; }
.stat-controls label { font-size: 13px; color: var(--muted); }
.stat-controls select { margin-left: 6px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: var(--surface); color: var(--ink); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.stat-block { background: var(--surface); padding: 16px; border-radius: var(--radius); }
.bar-chart { display: flex; flex-direction: column; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 50px; align-items: center; gap: 8px; font-size: 13px; }
.bar-row .bar { background: var(--bg); height: 14px; border-radius: 3px; overflow: hidden; }
.bar-row .bar > span { display: block; height: 100%; background: var(--accent); }
.bar-row .num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* Tables */
.content-table, .submissions-table { width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: var(--radius); overflow: hidden; }
.content-table th, .submissions-table th { text-align: left; padding: 10px 12px; font-size: 12px;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
.content-table td, .submissions-table td { padding: 12px; vertical-align: top; border-bottom: 1px solid var(--line); font-size: 14px; }
.content-table tr.is-hidden { color: var(--muted); }
.content-table .truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.submissions-controls { display: flex; gap: 12px; align-items: center; font-size: 13px; flex-wrap: wrap; }
.submissions-controls button { padding: 4px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 4px; }
.submissions-controls button:disabled { color: var(--muted); cursor: not-allowed; }

/* Dialogs */
dialog { border: none; border-radius: var(--radius); padding: 20px; max-width: 520px; width: 92vw; }
dialog::backdrop { background: var(--backdrop); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
dialog input[type="text"], dialog input[type="number"], dialog textarea, dialog select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; font: inherit;
  background: var(--surface); color: var(--ink); }
dialog label:has(input[type="checkbox"]) { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
dialog textarea { resize: vertical; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }
dialog menu button { padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; }
dialog menu .btn-primary { border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* Project detail (photo management) */
.project-detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.project-detail-header button { background: transparent; border: 1px solid var(--line); padding: 6px 12px; border-radius: 6px; }
.photo-section { background: var(--surface); padding: 16px; border-radius: var(--radius); margin-top: 16px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.photo-thumb { position: relative; aspect-ratio: 1; overflow: hidden; border-radius: 6px; background: var(--bg); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .photo-del { position: absolute; top: 4px; right: 4px; background: var(--photo-del-bg); color: white;
  border: none; width: 24px; height: 24px; border-radius: 50%; font-size: 14px; line-height: 1; cursor: pointer; }
.photo-upload { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; font-size: 13px; }

/* Submissions table now has more columns; let it scroll horizontally on
   narrow desktop windows rather than crowding labels. */
.submissions-table { font-size: 13px; }
.submissions-table td.truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Submission detail dialog */
.submission-dialog { max-width: 720px; }
.submission-detail { display: grid; gap: 18px; margin: 8px 0 4px; }
.sub-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 18px;
  margin: 0;
}
.sub-field { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); }
.sub-field dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; min-width: 88px; }
.sub-field dd { margin: 0; font-size: 14px; word-break: break-word; }
.sub-message h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }
.sub-message p { white-space: pre-wrap; margin: 0; padding: 12px; background: var(--bg); border-radius: var(--radius); font-size: 14px; }
.submission-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.submission-photo {
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
}
.submission-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.submission-photo:hover { border-color: var(--ink); }
.sub-photos-empty { color: var(--muted); font-size: 13px; font-style: italic; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--accent-ink); padding: 10px 18px; border-radius: 6px;
  font-size: 13px; box-shadow: var(--toast-shadow); z-index: 1000; }
.toast.is-error { background: var(--danger); }

@media (max-width: 640px) {
  .dash-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .dash-nav { flex-wrap: wrap; }
  .content-table thead, .submissions-table thead { display: none; }
  .content-table td, .submissions-table td { display: block; padding: 8px 12px; border: 0; }
  .content-table tr, .submissions-table tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
}
