/* Empire Estimators Project Dashboard — matches empire-dashboard .dark tokens.
   Dense and fast over decorative (SPEC.md section 7). No framework.
   Forced dark so the Projects app always feels continuous with the dashboard. */

:root {
  /* empire-dashboard .dark → hsl converted to hex approximations */
  --bg: #020817;                         /* hsl(222.2 84% 4.9%) */
  --surface: #020817;                    /* card ≈ background */
  --surface-2: #1e293b;                  /* hsl(217.2 32.6% 17.5%) secondary/muted/accent */
  --border: #1e293b;
  --text: #f8fafc;                       /* hsl(210 40% 98%) */
  --muted: #94a3b8;                      /* hsl(215 20.2% 65.1%) */
  --accent: #f8fafc;                     /* primary in dark = light pill */
  --accent-text: #020817;                /* primary-foreground on light pill */
  --link: #93c5fd;                       /* readable blue on dark */
  --row-hover: #0f172a;
  --input-bg: #0b1220;
  --error-bg: #3f1d1d;
  --error-border: #7f1d1d;
  --error-text: #fecaca;
  --ok-bg: #14261c;
  --ok-border: #166534;
  --ok-text: #86efac;
  --warn-bg: #2a2110;
  --warn-border: #854d0e;
  --warn-text: #fde68a;
  --radius: 8px;
  --sidebar-width: 256px;
  --header-height: 64px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; }

/* --- App shell (authenticated): sidebar + main column ------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
}

.brand-logo {
  height: 44px; /* empire-dashboard h-11 — JPG already has white plate */
  width: auto;
  display: block;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(420px, 42vw);
  font-size: 13px;
}

.sidenav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  overflow-y: auto;
}

.navicon {
  width: 20px;  /* h-5 w-5 */
  height: 20px;
  flex-shrink: 0;
}

.sidenav-group {
  padding-top: 12px;
}

.navlink {
  display: flex;
  align-items: center;
  gap: 12px; /* gap-3 */
  padding: 8px 12px; /* px-3 py-2 */
  border-radius: var(--radius); /* rounded-lg */
  color: var(--muted);
  text-decoration: none;
  font-size: 14px; /* text-sm */
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.navlink:hover {
  background: var(--surface-2);
  color: var(--text);
}

.navlink.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.navlink.is-active .badgecount {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 16px;
}

.sidebar-foot .app-version {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  text-align: left;
  max-width: none;
}

.app-column {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 100vh;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-height);
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.welcome {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.whoami {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.whoami form { margin: 0; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--link);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.thsort { color: inherit; text-decoration: none; }
.thsort:hover { color: var(--link); text-decoration: underline; }

/* Auth (signed-out) shell */
.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.auth-version {
  margin: 0 auto 20px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* --- Layout ------------------------------------------------------------ */

.wrap {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 48px;
  flex: 1;
}

.wrap--centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  max-width: none;
}

.pagehead {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}

.pagehead h1 { font-size: 20px; margin: 0; color: var(--text); }
.count { color: var(--muted); font-size: 13px; }

/* --- Flash messages ---------------------------------------------------- */

.flashes { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }

.flash {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.flash--error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }
.flash--ok    { background: var(--ok-bg);    border-color: var(--ok-border);    color: var(--ok-text); }
.flash--warn  { background: var(--warn-bg);  border-color: var(--warn-border);  color: var(--warn-text); }

/* --- Cards and forms --------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login p { margin: 0 0 20px; }

label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

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

button.primary,
a.primary {
  display: inline-block;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

button.primary:hover,
a.primary:hover { filter: brightness(0.94); }

.fineprint { margin: 16px 0 0; font-size: 12px; color: var(--muted); }

/* --- Table ------------------------------------------------------------- */

.tablewrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.grid { width: 100%; border-collapse: collapse; font-size: 13px; }

.grid th {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: var(--surface);
}

.grid td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--row-hover); }
.grid .title { font-weight: 500; }

/* --- Status pills ------------------------------------------------------ */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
}

.pill--approved,
.pill--closed { background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text); }

.pill--in_progress,
.pill--pdf_for_review,
.pill--esx_sent,
.pill--figures_entered,
.pill--figures_approved,
.pill--invoice_sent { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }

.empty { color: var(--muted); }
code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Filter bar --------------------------------------------------------- */

form.filters,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  margin-bottom: 14px;
}

form.filters input[type="text"],
form.filters select,
.filters input[type="text"],
.filters select,
.addrow select {
  /* Beat the global form control `width: 100%` / `margin-bottom` rules so
     the Projects filter bar lays out as a compact horizontal wrap row. */
  width: auto !important;
  max-width: none;
  margin: 0 !important;
  margin-bottom: 0 !important;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
}

form.filters input[type="text"],
.filters input[type="text"] {
  flex: 1 1 200px;
  min-width: 160px;
  max-width: 280px;
}

form.filters select,
.filters select {
  flex: 0 1 auto;
  min-width: 7.5rem;
  max-width: 11rem;
}

form.filters button.compact,
button.compact {
  width: auto !important;
  margin: 0 !important;
  padding: 6px 12px;
}

.clearlink { color: var(--muted); font-size: 13px; white-space: nowrap; }

.grid a { color: inherit; text-decoration: none; }
.grid a:hover { text-decoration: underline; color: var(--link); }

/* --- Project detail header ---------------------------------------------- */

.crumbs { margin-bottom: 10px; font-size: 13px; }
.crumbs a { color: var(--link); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.projhead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.projhead h1 { margin: 0 0 4px; font-size: 19px; line-height: 1.35; }
.submeta { margin: 0; font-size: 13px; }
.submeta a { color: var(--link); }
.headactions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--row-hover); border-color: var(--muted); }

/* --- Panels ------------------------------------------------------------- */

.panel {
  padding: 18px 20px;
  margin-bottom: 16px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.panel h2 + .steps { margin-bottom: 18px; }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } }

/* --- Status step bars --------------------------------------------------- */

.steps { display: flex; flex-wrap: wrap; gap: 6px; }

.step {
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.step:hover { background: var(--row-hover); color: var(--text); }

.step--done {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.step--current {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* --- Small pieces ------------------------------------------------------- */

.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { margin-left: auto; }
.inline { display: inline; }
.grid--tight td { padding: 7px 8px; }
.linkbtn--danger { color: var(--error-text); }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-2);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.tag--inbound  { background: var(--ok-bg);   border-color: var(--ok-border);   color: var(--ok-text); }
.tag--outbound { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }

.addrow { display: flex; gap: 8px; margin-top: 10px; }
.addrow select { flex: 1; min-width: 0; }

/* --- History ------------------------------------------------------------ */

.events {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 10px;
  max-height: 22rem; overflow-y: auto; overscroll-behavior: contain;
}
.events a { color: inherit; }
.events li:target, .msg:target { outline: 2px solid var(--link); outline-offset: 2px; }
.events li { border-left: 2px solid var(--border); padding-left: 10px; font-size: 13px; }

/* --- Message thread ----------------------------------------------------- */

.thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.msg {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--input-bg);
}

.msg--system { border-style: dashed; }

.msghead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.msgsubject { margin-top: 2px; }

.msgbody {
  margin: 8px 0 0;
  font: inherit;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* --- Billing panel ------------------------------------------------------ */

.ratebox {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ratelabel {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.rateamount {
  font-size: 20px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.ratemissing { color: var(--warn-text); font-size: 14px; font-weight: 500; }

.billingrow { display: flex; gap: 16px; flex-wrap: wrap; }
.billingrow > div { flex: 1; min-width: 170px; }
.billingrow input { width: 100%; }

.billingactions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.billingactions form { margin: 0; }

.rateinput { width: 110px; }
.grid input {
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.panel textarea {
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.panel select {
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.contactrow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.contactrow input { margin: 0; font-size: 12px; padding: 5px 7px; }
.contactrow input[type="text"] { width: 120px; }
.contactrow input[type="email"] { width: 200px; }

.addrow input {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  min-width: 0;
}

.addrow { flex-wrap: wrap; }
.rowmuted { opacity: 0.55; }

.badgecount {
  display: inline-block;
  min-width: 17px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  font-size: 11px;
  text-align: center;
  font-weight: 600;
}

.tag--warnflag {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
  text-transform: none;
  letter-spacing: 0;
}

.tag--reason { background: var(--surface-2); }

.matchwhy { margin-top: 4px; font-style: italic; }

.triagelist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.triageactions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.triageactions form { display: flex; gap: 8px; align-items: center; }
.triageactions select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  max-width: 380px;
  margin: 0;
}

.attachlist {
  list-style: none;
  margin: 10px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 4px;
  font-size: 12px;
}

.attachlist a { color: var(--link); }

/* --- Reply composer ----------------------------------------------------- */

.composer { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.composer textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.composerrow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.composerrow input[type="file"] { flex: 1; min-width: 220px; font-size: 12px; color: var(--muted); }
.composer .fineprint { margin-top: 10px; }

.checkline {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 10px; font-size: 13px; color: var(--muted);
}
.checkline input { margin: 0; }

.skeleton {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin: 0.75rem 0;
  padding: 0.6rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 2;
}

.skeleton input[type="text"] {
  margin: 0;
  padding: 0.15rem 0.35rem;
  font: inherit;
  background: var(--surface-2);
}

.skeleton .locked {
  padding: 0.15rem 0.35rem;
  background: var(--surface-2);
  border-radius: 3px;
  color: var(--text);
  white-space: nowrap;
}

.filelist { list-style: none; margin: 8px 0 0; padding: 0; }
.filelist li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--input-bg);
  font-size: 13px;
}
.filelist .filename {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.filelist .filesize { color: var(--muted); font-size: 12px; flex: none; }
.filelist .fileremove {
  flex: none; border: 0; background: none; cursor: pointer;
  color: var(--error-text); font-size: 18px; line-height: 1;
  padding: 0 4px;
}
.filelist .fileremove:hover { text-decoration: none; opacity: .7; }

.inlineform { display: inline-flex; gap: 6px; align-items: center; }
.inlineform select {
  font-size: 13px;
  padding: 2px 4px;
  margin: 0;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Settings tabs: pill buttons like empire-dashboard TabsList -------- */

.settings-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin: 0 0 18px;
  padding: 4px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.settings-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin: 0;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  background: transparent;
}

.settings-tabs a:hover {
  color: var(--text);
}

.settings-tabs a.is-active {
  color: var(--text);
  background: var(--bg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* Legacy page footer class (kept for safety if referenced elsewhere) */
.app-version {
  margin: 24px auto 16px;
  padding: 0 16px;
  max-width: 1100px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* --- Responsive: stack sidebar above content, no JS required ------------ */

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidenav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }
  .sidebar-foot { display: none; }
  .content-header { padding: 0 16px; }
  .welcome { font-size: 16px; }
  .wrap { padding: 16px 16px 40px; }
}
