/* =========================================================================
   AUTIN Task Tracker — hand-written stylesheet
   Operations dashboard: calm, legible, data-dense.
   Accent: indigo #3b5bdb.  Status: green / blue / red / amber.
   ========================================================================= */

:root {
  /* Surfaces & text */
  --bg:        #f7f8fa;
  --surface:   #ffffff;
  --surface-2: #f1f3f5;
  --border:    #e4e7eb;
  --border-strong: #cfd4da;

  --text:      #1f2933;
  --text-2:    #52606d;
  --text-3:    #7b8794;

  /* Accent */
  --accent:        #3b5bdb;
  --accent-hover:  #364fc7;
  --accent-active: #2f44ae;
  --accent-soft:   #eef1fd;
  --accent-ring:   rgba(59, 91, 219, 0.30);

  /* Semantic status */
  --green:  #16794c; --green-bg:  #e5f4ec;
  --blue:   #1c5fd0; --blue-bg:   #e6effc;
  --red:    #c0362c; --red-bg:    #fcebe9;
  --amber:  #96690d; --amber-bg:  #fcf3e0;

  /* Shape */
  --radius:    10px;
  --radius-sm: 7px;
  --radius-pill: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow:    0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);

  --sidebar-w: 230px;
  --topbar-h:  60px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
          "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

/* ---------- Reset-ish base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; color: var(--text); }
h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p  { margin: 0 0 1em; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* =========================================================================
   Shell
   ========================================================================= */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 20px;
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 14px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sidebar__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}
.sidebar__brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav__item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 550;
  line-height: 1.2;
  transition: background .12s ease, color .12s ease;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__icon { flex: none; opacity: .85; }
.nav__item--active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}
.nav__item--active .nav__icon { opacity: 1; }

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar__user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-weight: 650; font-size: .85rem;
  flex: none;
}
.topbar__meta { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.topbar__name { font-weight: 650; color: var(--text); }
.topbar__role { font-size: .78rem; text-transform: capitalize; }
.topbar__actions { display: flex; align-items: center; gap: 10px; }
.topbar__logout { text-decoration: none; }

.content {
  flex: 1;
  padding: 24px 28px 40px;
  max-width: 1240px;
  width: 100%;
}

/* =========================================================================
   Cards & KPIs
   ========================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.card__title {
  font-size: .82rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
  margin: 0 0 14px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi__value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.kpi__label {
  font-size: .8rem;
  color: var(--text-3);
  font-weight: 550;
}

/* =========================================================================
   Buttons
   ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
  text-decoration: none;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--primary:active { background: var(--accent-active); }

.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-2);
}
.btn--ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.btn--sm { padding: 6px 11px; font-size: .8rem; gap: 6px; }

/* =========================================================================
   Status chips
   ========================================================================= */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}
.chip::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
  opacity: .9;
}
.status-complete   { background: var(--green-bg); color: var(--green); border-color: rgba(22,121,76,.16); }
.status-onschedule { background: var(--blue-bg);  color: var(--blue);  border-color: rgba(28,95,208,.16); }
.status-late       { background: var(--red-bg);   color: var(--red);   border-color: rgba(192,54,44,.16); }
.status-future     { background: var(--amber-bg); color: var(--amber); border-color: rgba(150,105,13,.16); }

/* =========================================================================
   Tables
   ========================================================================= */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.table th, .table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: .74rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border-strong);
}
.table tbody tr { transition: background .1s ease; }
.table tbody tr:hover { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: none; }

/* Tables inside cards drop the card's own padding intrusion */
.card > .table, .card .table--tasks { margin: 0; }

.table--tasks td, .table--tasks th { padding-top: 8px; padding-bottom: 8px; }
.table--tasks .col-num { text-align: right; font-variant-numeric: tabular-nums; }

/* =========================================================================
   Tree rows (task hierarchy)
   ========================================================================= */
.tree-row td:first-child,
.tree-row > .tree-cell {
  padding-left: calc(14px + var(--level, 0) * 22px);
  position: relative;
}
/* connector guide */
.tree-row td:first-child::before,
.tree-row > .tree-cell::before {
  content: "";
  position: absolute;
  left: calc(6px + var(--level, 0) * 22px);
  top: 0; bottom: 0;
  border-left: 1px solid var(--border);
  opacity: .8;
}
.tree-row[style*="--level: 0"] td:first-child::before,
.tree-row[style*="--level:0"] td:first-child::before { display: none; }

.tree-row--parent {
  font-weight: 650;
  color: var(--text);
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}
.tree-row--parent:hover { background: var(--accent-soft); }
.tree-row--leaf { font-weight: 500; color: var(--text-2); }
.tree-row--leaf td:first-child { color: var(--text); }

.tree-toggle {
  display: inline-flex;
  width: 16px; margin-right: 4px;
  color: var(--text-3);
  flex: none;
}

/* =========================================================================
   Progress bar
   ========================================================================= */
.progress {
  --h: 7px;
  position: relative;
  height: var(--h);
  min-width: 90px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width .35s ease;
  min-width: 0;
}
/* Optional status-tinted progress bars if a status class is added alongside */
.progress__bar.status-complete   { background: var(--green); }
.progress__bar.status-onschedule { background: var(--blue); }
.progress__bar.status-late       { background: var(--red); }
.progress__bar.status-future     { background: var(--amber); }

.progress-cell { display: flex; align-items: center; gap: 9px; }
.progress-cell .progress { flex: 1; }
.progress-cell .progress-pct {
  font-variant-numeric: tabular-nums;
  font-size: .8rem;
  color: var(--text-2);
  min-width: 34px; text-align: right;
}

/* =========================================================================
   Forms
   ========================================================================= */
.form { max-width: 620px; display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-2);
}
.input, .form select, .form textarea {
  font-family: inherit;
  font-size: .9rem;
  color: var(--text);
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input::placeholder { color: var(--text-3); }
.input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.form textarea { min-height: 84px; resize: vertical; line-height: 1.5; }

.field--inline { flex-direction: row; align-items: center; gap: 10px; }
.form__actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }

.breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: .85rem;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.breadcrumb strong { color: var(--text); font-weight: 650; }
.breadcrumb .sep { color: var(--border-strong); }

/* =========================================================================
   Utilities
   ========================================================================= */
.muted { color: var(--text-3); }
.right { text-align: right; margin-left: auto; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: .75rem;
  font-weight: 600;
}

.flag-silent {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(192,54,44,.20);
  font-size: .74rem;
  font-weight: 650;
}
.flag-silent::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* Page header helper (used by feature pages) */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; }

/* =========================================================================
   htmx niceties
   ========================================================================= */
.htmx-indicator {
  opacity: 0;
  transition: opacity .15s ease;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}
/* Fade freshly swapped content in, avoiding a layout flash */
.htmx-settling { opacity: 0; }
[hx-swap], .htmx-added { transition: opacity .12s ease; }

.saved-flash {
  color: var(--green);
  font-size: .8rem;
  font-weight: 600;
}
#checkin-status { font-size: .8rem; }

/* =========================================================================
   Responsive — collapse sidebar to a horizontal top nav on small screens
   ========================================================================= */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar__brand {
    border-bottom: none;
    padding: 0 6px 0 0;
    margin-right: 4px;
    flex: none;
  }
  .sidebar__brand-text { display: none; }
  .nav {
    flex-direction: row;
    gap: 2px;
  }
  .nav__item { padding: 8px 10px; white-space: nowrap; }
  .nav__item span:not(.nav__icon) { display: none; }
  .nav__item--active span { display: inline; }

  .topbar { padding: 0 14px; }
  .content { padding: 18px 14px 32px; }

  .table thead th { top: 0; }
}

@media (max-width: 520px) {
  .topbar__meta { display: none; }
  .topbar__actions { gap: 6px; }
  .topbar__logout span { display: none; }
  .kpi__value { font-size: 1.6rem; }
}
