:root {
  --bg: #0f1220;
  --panel: #1a1f36;
  --panel-2: #232945;
  --border: #2e3556;
  --text: #e7e9f3;
  --muted: #9aa0be;
  --primary: #6366f1;
  --primary-hover: #4f52e0;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --ok: #22c55e;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.view { min-height: 100vh; }
[hidden] { display: none !important; }

/* ---- Cards ---- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---- Login ---- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.subtitle { margin: 0 0 6px; color: var(--muted); font-size: 14px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---- Password Box Inline Toggle ---- */
.password-wrapper {
  position: relative;
  width: 100%;
}
.password-wrapper input {
  padding-right: 40px !important;
}
.password-toggle-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s ease;
  z-index: 2;
}
.password-toggle-btn:hover {
  color: var(--text);
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--border); padding: 6px 10px; font-size: 13px; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.current-user { color: var(--muted); font-size: 13px; }

/* ---- Content ---- */
.content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; font-size: 17px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }
.actions-col { text-align: right; }
td.actions { text-align: right; display: flex; gap: 8px; justify-content: flex-end; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-ok { background: rgba(34,197,94,.15); color: var(--ok); }
.badge-no { background: rgba(154,160,190,.15); color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.you-tag { color: var(--primary); font-size: 12px; margin-left: 6px; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal { width: 100%; max-width: 420px; }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
#modal-fields { display: flex; flex-direction: column; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Impersonation banner ---- */
.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 24px;
  background: rgba(99,102,241,.18);
  border-bottom: 1px solid var(--primary);
  color: var(--text);
  font-size: 14px;
}
.banner .btn-sm { background: var(--primary); color: #fff; }
.banner .btn-sm:hover { background: var(--primary-hover); }

/* ---- Forced-change notice ---- */
.notice {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239,68,68,.12);
  border: 1px solid var(--danger);
  color: var(--text);
  font-size: 13px;
}

/* ---- Account view ---- */
.stack { display: flex; flex-direction: column; gap: 14px; max-width: 380px; }
.profile { display: grid; grid-template-columns: auto 1fr; gap: 10px 20px; margin: 0; }
.profile dt { color: var(--muted); font-size: 13px; }
.profile dd { margin: 0; font-size: 14px; }

/* ---- To-do list ---- */
.muted-text { color: var(--muted); font-size: 13px; margin: 0; }
.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.todo-item .todo-label { font-size: 15px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 130px; }
.todo-done { color: var(--ok); font-size: 15px; }

/* ---- History overlay ---- */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 40;
  overflow-y: auto;
}
.overlay-inner { max-width: 900px; margin: 0 auto; padding: 24px; }
.overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.overlay-head h2 { margin: 0; }
.overlay-body { display: flex; flex-direction: column; gap: 20px; }
.overlay-body h3 { margin: 0; font-size: 15px; }

.add-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.add-row label { flex-direction: column; }
.add-row input[type="date"], .add-row input[type="number"] { width: 170px; }
.add-row .error { flex-basis: 100%; }

/* ---- Graph ---- */
.graph-wrap { width: 100%; overflow-x: auto; }
.graph-wrap svg { display: block; width: 100%; height: auto; }
.graph-empty { color: var(--muted); text-align: center; padding: 40px 0; }
.g-axis { stroke: var(--border); stroke-width: 1; }
.g-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; opacity: .5; }
.g-line { fill: none; stroke: var(--primary); stroke-width: 2; }
.g-dot { fill: var(--primary); }
.g-label { fill: var(--muted); font-size: 11px; }

/* inline edit inputs in the chart table */
td .edit-input { width: 100px; }

/* ---- Photos gallery ---- */
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}
.gallery-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  display: block;
}
.gallery-del {
  position: absolute;
  top: 6px; right: 6px;
  border: none;
  background: rgba(0,0,0,.6);
  color: #fff;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.gallery-del:hover { background: var(--danger); }
.gallery-uploading {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}

/* ---- Fill-up / manager forms ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.select-row { display: flex; gap: 8px; align-items: center; }
.select-row select { flex: 1; }
#fillup-gallery:empty { display: none; }
.gallery-item .gallery-badge {
  position: absolute;
  bottom: 4px; left: 4px;
  background: rgba(0,0,0,.6);
  color: #fff; font-size: 10px;
  padding: 1px 5px; border-radius: 4px;
}

/* ---- Mini thumbnails (all fill-ups view) ---- */
.mini-thumb {
  width: 40px; height: 40px;
  object-fit: cover; border-radius: 4px;
  cursor: pointer; margin: 2px;
  border: 1px solid var(--border);
}

/* ---- Tag chips ---- */
.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; min-height: 24px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(99,102,241,.18);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 3px 6px 3px 10px;
  border-radius: 20px;
  font-size: 13px;
}
.tag-chip-x {
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px;
}
.tag-chip-x:hover { color: var(--danger); }
.tag-chip.tag-admin { background: rgba(239,68,68,.16); border-color: var(--danger); }
.tags-cell { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- Camera modal ---- */
.camera-modal { max-width: 560px; }
.camera-stage { background: #000; border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.camera-stage video { width: 100%; display: block; max-height: 60vh; }

/* ---- Image lightbox ---- */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 60;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---- Misc ---- */
.error { color: var(--danger); font-size: 13px; margin: 4px 0 0; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 8px;
  font-size: 14px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.toast-error { border-color: var(--danger); }
.toast.toast-ok { border-color: var(--ok); }

/* ---- Sun Times Banner ---- */
.sun-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  background: linear-gradient(135deg, rgba(251, 146, 60, 0.12), rgba(99, 102, 241, 0.12));
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  animation: fadeIn 0.4s ease-out;
}
.sun-banner-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}
.sun-banner-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sun-banner-icon {
  font-size: 18px;
}
.sun-banner-label {
  color: var(--muted);
  font-weight: 500;
}
.sun-banner-value {
  font-weight: 600;
  color: #fff;
}
.sun-banner-coords {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
}
.sun-banner-numbers {
  font-size: 18px;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.15em;
  margin-top: 2px;
}
.sun-banner-christmas {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
  margin-top: 4px;
}
.sun-loading {
  color: var(--muted);
  font-style: italic;
}
.sun-error {
  color: var(--muted);
  font-size: 13px;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Steps Hourly Goals Grid ---- */
.steps-hourly-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.steps-hourly-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  text-align: center;
}
.steps-hourly-time {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.steps-hourly-target {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.steps-start-hour-select {
  width: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 2px;
}
.steps-start-hour-select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}
