/* ==========================================================================
   RedHorse Ops Console
   Dense, dark, keyboard-friendly. This is a tool, not a website: the goal is
   maximum information per screen and zero clicks between seeing something
   and changing it.
   ========================================================================== */
:root {
  --bg:        #16161a;
  --panel:     #1d1d22;
  --panel-2:   #24242b;
  --raised:    #2b2b33;
  --line:      #33333d;
  --line-soft: #26262e;

  --text:  #ecedf0;
  --dim:   #9a9aa6;
  --dimmer:#6b6b78;

  --red:      #d81e2c;
  --red-ink:  #ff6069;
  --red-soft: rgba(216,30,44,0.12);

  --good:  #3fbf7f;
  --warn:  #e0a33a;
  --bad:   #ef5b5b;

  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; }

/* ------------------------------------------------------------------ chrome */
.top {
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1.1rem; height: 48px;
  background: #101013; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand {
  font-weight: 700; letter-spacing: 0.02em; text-decoration: none;
  display: flex; align-items: center; gap: 0.5rem;
}
.brand .mark {
  background: var(--red); color: #fff; padding: 0.1rem 0.4rem;
  border-radius: 4px; font-size: 12px; letter-spacing: 0.06em;
}
.top nav { display: flex; gap: 0.35rem; margin-left: 0.75rem; }
.top nav a {
  padding: 0.3rem 0.7rem; border-radius: 6px; text-decoration: none;
  color: var(--dim); font-weight: 500;
}
.top nav a:hover { background: var(--panel-2); color: var(--text); }
.top nav a.on { background: var(--red-soft); color: var(--red-ink); }
.top .spacer { margin-left: auto; }

.wrap { padding: 1.1rem; max-width: 1500px; margin: 0 auto; }

/* ------------------------------------------------------------------ filters */
.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.9rem; }
.tab {
  padding: 0.32rem 0.7rem; border-radius: 999px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--dim); font-size: 13px; white-space: nowrap;
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.on { background: var(--red); border-color: var(--red); color: #fff; }
.tab .n { opacity: 0.7; margin-left: 0.3rem; font-variant-numeric: tabular-nums; }
.tab.alert { border-color: var(--warn); color: var(--warn); }
.tab.alert.on { background: var(--warn); border-color: var(--warn); color: #16161a; }

.searchbar { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; }
input[type=search], input[type=text], input[type=date], select, textarea {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 0.4rem 0.55rem; font: inherit; font-size: 13px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--red); background: var(--panel-2);
}
.searchbar input[type=search] { flex: 1; max-width: 340px; }

/* -------------------------------------------------------------------- table */
table.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--dimmer); font-weight: 600;
  padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 48px; background: var(--bg); z-index: 10;
}
.grid td {
  padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.grid tbody tr:hover { background: var(--panel); }
.grid .name { font-weight: 600; }
.grid .name a { text-decoration: none; }
.grid .name a:hover { color: var(--red-ink); }
.muted { color: var(--dimmer); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }

/* Inline controls sit flush in the cell until hovered, so the table reads as
   data rather than as a form. */
.grid select, .grid input {
  background: transparent; border: 1px solid transparent;
  padding: 0.2rem 0.3rem; width: 100%;
}
.grid select:hover, .grid input:hover { border-color: var(--line); background: var(--panel-2); }
.grid select:focus, .grid input:focus { border-color: var(--red); background: var(--panel-2); }
.grid input.saved, .grid select.saved { border-color: var(--good); }

/* ------------------------------------------------------------------- pills */
.pill {
  display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  border: 1px solid var(--line); color: var(--dim); white-space: nowrap;
}
.pill.new       { border-color: #3c5a7a; color: #8fbce8; }
.pill.contacted { border-color: #6b5a2a; color: #e0c07a; }
.pill.quoted    { border-color: #6b4a2a; color: #e8a76a; }
.pill.client    { border-color: #2f6b4a; color: #6fd6a0; }
.pill.declined  { border-color: #5a3236; color: #d98b90; }
.pill.past      { border-color: #3d3d47; color: #8b8b98; }

/* Due dates earn colour; everything else stays quiet. */
.due-over  { color: var(--bad);  font-weight: 700; }
.due-today { color: var(--warn); font-weight: 700; }
.due-soon  { color: var(--text); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 0.32rem 0.65rem; font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--raised); border-color: var(--dimmer); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #ef2b3a; }
.btn.tiny { padding: 0.16rem 0.4rem; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.rowacts { display: flex; gap: 0.25rem; }

/* ------------------------------------------------------------------- cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 0.85rem; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 0.9rem 1rem;
}
.card h3 { margin: 0 0 0.15rem; font-size: 15px; }
.card h3 a { text-decoration: none; }
.card .sub { color: var(--dimmer); font-size: 12px; margin-bottom: 0.6rem; }
.card.bad { border-color: #5a2f33; }
.card.ok  { border-color: #2f5a45; }

.kv { display: grid; grid-template-columns: 88px 1fr; gap: 0.2rem 0.6rem; font-size: 12.5px; }
.kv dt { color: var(--dimmer); }
.kv dd { margin: 0; word-break: break-word; }

.status { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 12px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--good); }
.dot.bad { background: var(--bad); }
.dot.none { background: var(--dimmer); }

/* -------------------------------------------------------------- lead detail */
.split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.1rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.55rem 0; border-bottom: 1px solid var(--line-soft); display: flex; gap: 0.7rem; }
.timeline .when { color: var(--dimmer); font-size: 11.5px; font-family: var(--mono); white-space: nowrap; }
.timeline .kind {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--red-ink); font-weight: 700; white-space: nowrap;
}
.field-row { display: grid; grid-template-columns: 110px 1fr; gap: 0.5rem; align-items: center; margin-bottom: 0.45rem; }
.field-row label { color: var(--dimmer); font-size: 12px; }
.field-row input, .field-row select { width: 100%; }

h1 { font-size: 19px; margin: 0 0 0.15rem; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dimmer); margin: 0 0 0.6rem; }
.sub { color: var(--dim); }

pre.out {
  background: #0e0e11; border: 1px solid var(--line); border-radius: 7px;
  padding: 0.7rem 0.85rem; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; max-height: 340px; overflow: auto; margin: 0.7rem 0 0;
}
.empty { color: var(--dimmer); padding: 2rem 0; text-align: center; }
.flash { position: fixed; right: 1rem; bottom: 1rem; background: var(--good);
         color: #10231a; padding: 0.5rem 0.9rem; border-radius: 7px;
         font-weight: 700; font-size: 13px; opacity: 0; transition: opacity .2s; }
.flash.show { opacity: 1; }

@media (max-width: 900px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------- inline editors */
/* These replaced prompt(). A browser can suppress a dialog silently; it
   cannot silently suppress a text input, so the action is always visible. */
.noteedit { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.noteedit input[type=text] { flex: 1; min-width: 220px; background: var(--panel-2); }
.noterow > td { background: var(--panel-2); padding: 0.55rem 0.6rem; }
.newlead { margin-bottom: 0.9rem; }

/* Most recent note, shown under the company so a save is visibly a save. */
.lastnote {
  color: var(--dim); font-size: 12px; margin-top: 0.15rem;
  max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 400;
}

/* ------------------------------------------------------------ undo + delete */
.flash.undo {
  display: flex; align-items: center; gap: 0.7rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line);
}
.flash.undo .btn { background: var(--red); border-color: var(--red); color: #fff; }
.flash.undo .btn:hover { background: #ef2b3a; }

.timeline li .grow { flex: 1; }
.timeline li .del {
  opacity: 0; padding: 0 0.4rem; line-height: 1.4;
  color: var(--dim); background: transparent; border-color: transparent;
}
.timeline li:hover .del { opacity: 1; }
.timeline li .del:hover { color: var(--bad); border-color: var(--bad); background: transparent; }

/* ---------------------------------------------------------------- payments */
.top nav .badge {
  display: inline-block; margin-left: 0.35rem; padding: 0 0.32rem;
  background: var(--bad); color: #fff; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; vertical-align: 1px;
}
.totals { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 1rem; }
.total {
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 0.6rem 1rem; min-width: 150px;
}
.total.bad { border-color: #5a2f33; }
.total .label {
  display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--dimmer); font-weight: 600;
}
.total .amt {
  display: block; font-family: var(--mono); font-size: 19px;
  font-weight: 600; margin-top: 0.15rem;
}
.total.bad .amt { color: var(--bad); }
.rowacts .del { color: var(--dim); }
.rowacts .del:hover { color: var(--bad); border-color: var(--bad); }

/* -------------------------------------------------------------------- login */
body.loginpage {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.loginbox {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 11px; padding: 1.6rem 1.5rem;
  width: 100%; max-width: 330px;
}
.loginbox label {
  display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--dimmer); font-weight: 600;
  margin-bottom: 0.3rem;
}
.loginbox input[type=password] { width: 100%; font-size: 15px; padding: 0.55rem 0.6rem; }
.loginerr {
  background: rgba(239,91,91,0.12); border: 1px solid #5a2f33;
  color: #ffb3b3; border-radius: 6px; padding: 0.5rem 0.7rem;
  font-size: 13px; margin: 0 0 0.9rem;
}
