/*
 * PropSquare FMS — dashboard design system (SPECIFICATION §3, §7).
 *
 * A self-contained, Node-free stylesheet for the server-rendered HTMX/Alpine
 * shell. We deliberately ship a curated utility + component sheet rather than a
 * Tailwind build pipeline: §2/§5 cap the stack at "two hard dependencies
 * (Python + Postgres)" and "boring, minimal toolchain". A Tailwind/PostCSS build
 * can be introduced in Phase 2 if the utility surface outgrows this file.
 *
 * Vendored and served locally (WhiteNoise) so the PWA shell works offline.
 */

/* ---- Design tokens -------------------------------------------------------- */
:root {
  --brand: #2563eb;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-50: #eff6ff;
  --ink: #0f172a;        /* slate-900 — nav + headings */
  --ink-700: #334155;
  --muted: #64748b;      /* slate-500 */
  --line: #e2e8f0;       /* slate-200 */
  --surface: #f8fafc;    /* slate-50 — app background */
  --card: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --info: #0369a1;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, .15), 0 8px 10px -6px rgba(15, 23, 42, .1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

/* ---- Reset ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, figure { margin: 0; }
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }
button { font-family: inherit; }

/* ---- Layout --------------------------------------------------------------- */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.app-main { padding: 28px 0 64px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.grid { display: grid; gap: 18px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---- Top navigation ------------------------------------------------------- */
.topnav {
  background: var(--ink);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow);
}
.topnav .container { display: flex; align-items: center; gap: 18px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #fff; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand-600), #38bdf8);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px;
}
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  color: #cbd5e1; padding: 8px 12px; border-radius: var(--radius-sm);
  font-weight: 500; font-size: 14px; white-space: nowrap;
}
.nav-link:hover { color: #fff; background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav-link.is-active { color: #fff; background: rgba(255, 255, 255, .14); }
.nav-link.is-soon { color: #94a3b8; cursor: default; }
.nav-link.is-soon:hover { background: transparent; color: #94a3b8; }

/* ---- Dropdown (Alpine-driven) -------------------------------------------- */
.menu { position: relative; }
.menu-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, .08); color: #fff;
  border: 1px solid rgba(255, 255, 255, .14);
  padding: 7px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
}
.menu-btn:hover { background: rgba(255, 255, 255, .16); }
.menu-btn .caret { font-size: 10px; opacity: .8; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50;
}
.menu-label { padding: 8px 10px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--muted); font-weight: 700; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: var(--radius-sm); border: 0; background: none;
  text-align: left; color: var(--ink); font-size: 14px; cursor: pointer;
}
.menu-item:hover { background: var(--surface); text-decoration: none; }
.menu-item.is-current { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.menu-item .role { margin-left: auto; font-size: 11px; color: var(--muted); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

/* ---- Cards ---------------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card-head { padding: 16px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.card-title { font-size: 16px; font-weight: 650; }
.nav-card {
  display: flex; flex-direction: column; gap: 6px; padding: 18px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--ink); transition: border-color .12s, box-shadow .12s, transform .12s;
}
.nav-card:hover { text-decoration: none; border-color: #cbd5e1; box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.nav-card.is-soon { opacity: .65; pointer-events: none; }
.nav-card .ico { font-size: 22px; }
.nav-card .t { font-weight: 650; }
.nav-card .d { font-size: 13px; color: var(--muted); }

/* ---- Typography helpers --------------------------------------------------- */
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.page-sub { color: var(--muted); font-size: 14px; }
.eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px; color: var(--brand-700); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- Badges --------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface); color: var(--ink-700);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }

/* ---- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand-600); color: #fff; }
.btn-primary:hover { background: var(--brand-700); color: #fff; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ---- Forms ---------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-700); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.field .helptext { font-size: 12px; color: var(--muted); }
/* Standalone control (outside a .field), e.g. inline filters / action forms. */
.input {
  width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink);
}
.input:focus {
  outline: none; border-color: var(--brand-600); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.field ul { margin: 4px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.errorlist { list-style: none; margin: 0 0 12px; padding: 0; }
.errorlist li { color: var(--danger); font-size: 13px; }

/* ---- Alerts --------------------------------------------------------------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; border: 1px solid transparent; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.alert-info { background: var(--info-bg); color: var(--info); border-color: #bae6fd; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #fde68a; }

/* ---- Auth screens --------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1e293b, var(--surface)); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card { padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.auth-brand .brand-mark { width: 36px; height: 36px; font-size: 16px; }
.auth-brand .name { font-weight: 800; font-size: 18px; color: var(--ink); }
.auth-foot { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }

/* ---- Offline page --------------------------------------------------------- */
.center-screen { min-height: 70vh; display: grid; place-items: center; text-align: center; padding: 24px; }

/* ---- Toolbar / lists / tables --------------------------------------------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 13px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--ink-700); background: var(--card);
}
.chip:hover { text-decoration: none; background: var(--surface); }
.chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip.is-active:hover { background: var(--ink); }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.table th {
  text-align: left; padding: 11px 16px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.table tbody tr:last-child td { border-bottom: 0; }
table.table tbody tr:hover { background: var(--surface); }
.rowlink { font-weight: 600; }
.mono { font-variant-numeric: tabular-nums; color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

/* ---- Detail layout -------------------------------------------------------- */
.detail-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.msg { padding: 10px 13px; border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 8px; }
.msg.inbound { border-left: 3px solid var(--brand-600); }
.msg.outbound { border-left: 3px solid var(--muted); }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
select.input, .field select { appearance: auto; }

/* ---- Responsive ----------------------------------------------------------- */
.only-mobile { display: none; }
@media (max-width: 820px) { .detail-grid { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  .nav-links.desktop { display: none; }
  .only-mobile { display: flex; }
  .hide-mobile { display: none; }
  .topnav .container { gap: 10px; }
  .app-main { padding: 20px 0 56px; }
}
