/* ============================================================
   Base — reset, typography, app shell, components
   Follows the AGENTiX component language so the two products read
   as one system.
   ============================================================ */

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

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.5;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.muted, .task-sub, .faint { color: hsl(var(--muted-foreground)); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.text-cyan { color: var(--cyan); }

@keyframes fadeUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin  { to { transform: rotate(360deg); } }

/* Cyan glow, used sparingly (auth, empty states) ------------------ */
.cyan-glow {
  position: absolute;
  border-radius: 50%;
  background: hsl(190 100% 50% / 0.10);
  filter: blur(100px);
  pointer-events: none;
  z-index: 0;
}

/* ── app shell ──────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

/* Sidebar (dark) -------------------------------------------------- */
.sidebar {
  background: var(--dark-bg);
  color: var(--white);
  border-right: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  padding: var(--space-lg) var(--space-md);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px var(--space-lg);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--white);
}
.logo-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--accent-gradient);
  display: grid; place-items: center;
  color: #000; font-weight: 800; font-size: 12px;
  flex-shrink: 0;
}
.sidebar-brand-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.4);
  padding: var(--space-md) 12px 8px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.entity {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.entity:hover { color: var(--white); background: rgba(255, 255, 255, 0.06); }
.entity.active { color: #000; background: hsl(var(--primary)); font-weight: 600; }
.entity-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.entity.active .entity-dot { background: #000 !important; }

.sidebar-divider { height: 1px; background: rgba(255, 255, 255, 0.12); margin: var(--space-md) 12px; border: none; }

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: var(--space-md);
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 6px 12px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-gradient);
  color: #000; font-weight: 700; font-size: 13px;
  display: grid; place-items: center; flex-shrink: 0;
}
.sidebar-user-meta { min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: rgba(255, 255, 255, 0.5); }
.sidebar-foot-links { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.sidebar-foot-links a {
  font-size: 13px; color: rgba(255, 255, 255, 0.6);
  padding: 8px 12px; border-radius: var(--radius-sm);
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.sidebar-foot-links a:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.sidebar-credit { font-size: 11px; color: rgba(255, 255, 255, 0.35); padding: 10px 12px 0; line-height: 1.5; }

/* Main column ----------------------------------------------------- */
.main-col { display: flex; flex-direction: column; min-width: 0; background: var(--gray-soft); }

.topbar {
  height: var(--topbar-height);
  background: var(--white);
  border-bottom: 1px solid var(--gray-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 0 var(--space-xl);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-sm); }
.topbar-date { font-size: 13px; color: hsl(var(--muted-foreground)); white-space: nowrap; }

.main { padding: var(--space-xl) var(--space-2xl); max-width: 1280px; width: 100%; margin: 0 auto; }

.menu-toggle {
  display: none;
  width: 38px; height: 38px;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-border);
  background: var(--white);
  cursor: pointer;
}
.menu-toggle span { display: block; width: 16px; height: 2px; background: #000; margin: 3px 0; border-radius: 2px; }
.sidebar-backdrop { display: none; }

/* Weather chip ---------------------------------------------------- */
.weather-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--gray-border);
  background: var(--gray-soft);
  white-space: nowrap;
}
.weather-chip.weather-dry { color: var(--warning-ink); background: var(--warning-tint); border-color: var(--warning-line); }
.weather-chip.weather-wet { color: var(--cyan-ink); background: var(--cyan-tint); border-color: var(--cyan-line); }

/* ── typography blocks ──────────────────────────────────────────── */

.page-head { margin-bottom: var(--space-xl); display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-md); flex-wrap: wrap; }
.page-eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: hsl(var(--muted-foreground)); margin-bottom: 6px; }
.page-title { font-size: 30px; font-weight: 800; letter-spacing: -0.025em; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-md); margin-bottom: var(--space-md); flex-wrap: wrap; }
.section-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.section-note { font-size: 13.5px; color: hsl(var(--muted-foreground)); }

/* ── panels and stat tiles ──────────────────────────────────────── */

.panel {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-md); margin-bottom: var(--space-lg); flex-wrap: wrap; }
.panel-title { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: hsl(var(--muted-foreground)); }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-lg); margin-bottom: var(--space-lg); }
.stats-row.four { grid-template-columns: repeat(4, 1fr); }
.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: border-color var(--dur-slow) var(--ease), box-shadow var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.stat-card:hover { border-color: hsl(190 100% 50% / 0.3); box-shadow: var(--shadow-card); transform: translateY(-2px); }
.stat-card-label { font-size: 12.5px; font-weight: 600; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card-value { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin-top: 8px; }
.stat-card-value.pine   { color: var(--cyan); }
.stat-card-value.rust   { color: var(--danger); }
.stat-card-value.timber { color: var(--warning); }

/* ── buttons ────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px; line-height: 1;
  border: 1px solid var(--gray-border);
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { border-color: hsl(190 100% 50% / 0.6); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--black); color: var(--white); border-color: transparent; }
.btn-primary:not(:disabled):hover {
  box-shadow: 0 0 0 1px hsl(190 100% 50% / 0.6), 0 8px 24px hsl(190 100% 50% / 0.25);
  border-color: hsl(190 100% 50% / 0.6);
}
.btn-accent { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
.btn-accent:not(:disabled):hover { filter: brightness(1.05); box-shadow: 0 8px 24px hsl(190 100% 50% / 0.35); }
.btn-danger { background: var(--white); color: var(--danger); border-color: var(--gray-border); }
.btn-danger:not(:disabled):hover { border-color: var(--danger); background: #fef2f2; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-row { display: flex; gap: var(--space-sm); flex-wrap: wrap; }

/* ── pills / badges ─────────────────────────────────────────────── */

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--gray-border);
  background: var(--gray-soft);
  color: var(--black);
  white-space: nowrap;
}
.pill-done, .pill-delivered   { color: var(--success-ink); background: var(--success-tint); border-color: var(--success-line); }
.pill-in_use, .pill-in_progress, .pill-available { color: var(--cyan-ink); background: var(--cyan-tint); border-color: var(--cyan-line); }
.pill-not_started             { color: var(--gray-muted-text); background: var(--gray-soft); border-color: var(--gray-border); }
.pill-on_hold, .pill-repair, .pill-attention, .pill-unavailable { color: var(--danger-ink); background: var(--danger-tint); border-color: var(--danger-line); }
.pill-ghost { background: transparent; }

/* ── tables ─────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border: 1px solid var(--gray-border); border-radius: var(--radius-md); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
.data-table th {
  background: var(--gray-soft);
  color: var(--black);
  font-weight: 600;
  text-align: left;
  padding: 12px 16px;
  white-space: nowrap;
  border-bottom: 1px solid var(--gray-border);
  font-size: 13px;
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--gray-border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafafa; }
.data-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.empty { text-align: center; padding: var(--space-2xl) var(--space-lg); color: hsl(var(--muted-foreground)); font-size: 14px; }

/* ── task list ──────────────────────────────────────────────────── */

.task-list { display: flex; flex-direction: column; }
.task-row { display: flex; align-items: flex-start; gap: var(--space-md); padding: var(--space-md) 0; border-top: 1px solid var(--gray-border); }
.task-row:first-child { border-top: none; padding-top: 0; }
.task-check {
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 1.5px solid var(--gray-border);
  background: var(--white);
  flex-shrink: 0; margin-top: 2px;
  position: relative; cursor: pointer; padding: 0;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.task-check:hover:not(:disabled) { border-color: var(--cyan); }
.task-check:disabled { cursor: default; opacity: 0.5; }
.task-check.done { background: hsl(var(--primary)); border-color: hsl(var(--primary)); }
.task-check.done::after {
  content: "";
  position: absolute; left: 6px; top: 2px;
  width: 5px; height: 10px;
  border: solid #000; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14.5px; font-weight: 600; margin-bottom: 2px; }
.task-title.done { color: hsl(var(--muted-foreground)); text-decoration: line-through; text-decoration-color: var(--gray-border); }
.task-sub { font-size: 13px; }
.task-meta { display: flex; gap: var(--space-sm); align-items: center; flex-wrap: wrap; margin-top: 8px; }
.task-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.task-time { font-size: 12.5px; color: hsl(var(--muted-foreground)); font-family: var(--font-mono); white-space: nowrap; }

/* ── forms ──────────────────────────────────────────────────────── */

.field { margin-bottom: var(--space-md); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
label.lbl { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus, select.input:focus, textarea.input:focus {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(190 100% 50% / 0.15);
}
textarea.input { resize: vertical; min-height: 96px; }
select.input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--gray-muted-text) 50%),
                    linear-gradient(135deg, var(--gray-muted-text) 50%, transparent 50%);
  background-position: right 16px top 20px, right 11px top 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.hint { font-size: 12px; color: hsl(var(--muted-foreground)); margin-top: 6px; }
.check-inline { display: flex; align-items: center; gap: 9px; font-size: 13.5px; cursor: pointer; user-select: none; }
.check-inline input { width: 16px; height: 16px; accent-color: var(--cyan); cursor: pointer; flex-shrink: 0; }

.form-alert { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13.5px; margin-bottom: var(--space-md); border: 1px solid transparent; }
.form-alert.err  { background: var(--danger-tint);  color: var(--danger-ink);  border-color: var(--danger-line); }
.form-alert.ok   { background: var(--success-tint); color: var(--success-ink); border-color: var(--success-line); }
.form-alert.warn { background: var(--warning-tint); color: var(--warning-ink); border-color: var(--warning-line); }

/* ── auth (dark, cyan glow) ─────────────────────────────────────── */

.auth-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--space-lg);
  background: var(--dark-bg);
  color: var(--white);
  position: relative;
  overflow: hidden;
}
.auth-wrap .cyan-glow.one { width: 480px; height: 480px; top: -120px; right: -80px; }
.auth-wrap .cyan-glow.two { width: 420px; height: 420px; bottom: -160px; left: -120px; }

.auth-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  background: var(--dark-card);
  border: 1px solid var(--dark-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  animation: fadeUp var(--dur-slow) var(--ease) both;
}
.auth-card.wide { max-width: 560px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.auth-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin-top: var(--space-lg); }
.auth-sub { color: var(--dark-muted-text); margin-top: 8px; margin-bottom: var(--space-xl); font-size: 14px; }
.auth-card label.lbl { color: rgba(255, 255, 255, 0.85); }
.auth-card .input { background: rgba(255, 255, 255, 0.04); border-color: var(--dark-border); color: #fff; }
.auth-card .input::placeholder { color: rgba(255, 255, 255, 0.35); }
.auth-card .input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px hsl(190 100% 50% / 0.2); }
.auth-card .hint { color: rgba(255, 255, 255, 0.45); }
.auth-card .check-inline { color: var(--dark-muted-text); }
.auth-card .btn-primary { background: hsl(var(--primary)); color: #000; }
.auth-card .btn-primary:not(:disabled):hover { filter: brightness(1.05); box-shadow: 0 8px 24px hsl(190 100% 50% / 0.35); }
.auth-foot { margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--dark-border); font-size: 12.5px; color: rgba(255, 255, 255, 0.45); text-align: center; line-height: 1.6; }

/* ── toast ──────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed; top: 20px; right: 20px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
  pointer-events: none;
}
.toast {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--black);
  color: var(--white);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.25);
  font-size: 14px;
  pointer-events: auto;
  border-left: 3px solid var(--cyan);
  animation: fadeUp var(--dur-fast) var(--ease);
}
.toast.ok  { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }

/* ── modal ──────────────────────────────────────────────────────── */

.modal-root {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-lg);
  animation: fadeIn 0.2s var(--ease);
}
/* The [hidden] attribute sets display:none, but the rule above outranks it.
   Without this the closed modal stays a full-screen layer over the page and
   swallows every click. */
.modal-root[hidden] { display: none; }

.modal-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 0.45); }
.modal-card {
  position: relative;
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.4);
  padding: var(--space-lg);
  animation: fadeUp var(--dur-fast) var(--ease);
}
.modal-card.wide { max-width: 720px; }
.modal-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.modal-sub { color: hsl(var(--muted-foreground)); font-size: 14px; margin-top: 4px; margin-bottom: var(--space-lg); }
.modal-body { margin-top: var(--space-md); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-sm); margin-top: var(--space-lg); padding-top: var(--space-md); border-top: 1px solid var(--gray-border); }

/* ── responsive ─────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform var(--dur-fast) var(--ease);
    z-index: 60;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .sidebar-backdrop,
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 50; }
  .menu-toggle { display: grid; }
  .topbar { padding: 0 var(--space-md); }
  .topbar-date { display: none; }
  .main { padding: var(--space-lg) var(--space-md); }
  .stats-row, .stats-row.four { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .stats-row, .stats-row.four { grid-template-columns: 1fr; }
  .page-title { font-size: 24px; }
  .panel { padding: var(--space-md); }
  .auth-card { padding: var(--space-lg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── print: the weekly report is meant to be handed over ────────── */

@media print {
  .sidebar, .topbar, .btn, .toast-stack, .modal-root, .filter-bar, .menu-toggle { display: none !important; }
  .app { display: block; }
  .main-col { background: #fff; }
  .main { padding: 0; max-width: none; }
  .panel, .stat-card, .report-figure { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
