/* Empire Project Hub — internal work tool.
   Dense and fast over decorative (SPEC.md section 7). No framework. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1b1f24;
  --muted: #6b7480;
  --accent: #1f5fa9;
  --accent-text: #ffffff;
  --error-bg: #fdecec;
  --error-border: #f0b4b4;
  --error-text: #8c1c1c;
  --ok-bg: #e9f6ec;
  --ok-border: #b3ddbf;
  --ok-text: #17603a;
  --warn-bg: #fdf4e3;
  --warn-border: #ecd39a;
  --warn-text: #7a5312;
  --row-hover: #f0f4f9;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --surface: #1e2227;
    --border: #333a42;
    --text: #e6e9ed;
    --muted: #98a2ae;
    --accent: #5b9bd8;
    --accent-text: #10151a;
    --error-bg: #3a1f1f;
    --error-border: #6b3333;
    --error-text: #f2b8b8;
    --ok-bg: #16301f;
    --ok-border: #2f5c3f;
    --ok-text: #a6dcb8;
    --warn-bg: #332a15;
    --warn-border: #5f4d24;
    --warn-text: #e8ce93;
    --row-hover: #252a31;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -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; }

/* --- Top bar ----------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; text-decoration: none; color: var(--text); }

.topnav { flex: 1; display: flex; gap: 16px; }
.topnav a { color: var(--muted); text-decoration: none; padding: 4px 0; }
.topnav a:hover { color: var(--text); }

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

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

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

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }

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

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

.pagehead h1 { font-size: 20px; margin: 0; }
.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);
}

.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"] {
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button.primary {
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.primary:hover { filter: brightness(1.08); }

.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;
}

.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(--bg);
  font-size: 11px;
  white-space: nowrap;
}

/* Terminal-ish states read green, in-flight states read amber. */
.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; }

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

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.filters input[type="text"],
.filters select,
.addrow select {
  margin: 0;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.filters input[type="text"] { width: 260px; }
button.compact { width: auto; padding: 7px 14px; }
.clearlink { color: var(--muted); font-size: 13px; }

.grid a { color: inherit; text-decoration: none; }
.grid a:hover { text-decoration: underline; }

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

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

.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(--accent); }
.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);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

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

/* --- 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);
  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(--bg);
  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 ------------------------------------------------------------ */

/* Bounded so a long-running project cannot push everything below it off the
   screen. Newest is already first, so the useful end is the visible one.
   Presentation only: no script scrolls this, and it works with JS off. */
.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(--accent); 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(--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;
}

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

.ratebox {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--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(--surface);
  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(--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(--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(--surface);
  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;
}

.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(--bg); }

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

.triagelist { list-style: none; margin: 0; padding: 0; }

.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(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  max-width: 380px;
}

.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(--accent); }

/* --- 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(--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; }

/* Opt-in control beside an add button: the default is off and must look it. */
.checkline {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 10px; font-size: 13px; color: var(--muted);
}
.checkline input { margin: 0; }

/* Notification control board (SPEC.md §6.7).

   The skeleton reads as one sentence: locked parts and editable runs sit on a
   single wrapped line so an admin sees the message they are editing, not a
   column of unlabelled boxes. */
.skeleton {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin: 0.75rem 0;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  line-height: 2;
}

.skeleton input[type="text"] {
  margin: 0;
  padding: 0.15rem 0.35rem;
  font: inherit;
}

/* Visibly not editable. The prefix and the placeholders are the parts an
   admin cannot change, and they should not look like fields that are merely
   disabled today. */
.skeleton .locked {
  padding: 0.15rem 0.35rem;
  background: var(--border);
  border-radius: 3px;
  color: var(--text);
  white-space: nowrap;
}
