/* Collins Invoices — "Modern Studio" theme (design turn 2)
   Sidebar app, cool neutrals, softer shapes, oxblood as the single accent. */

@font-face { font-family: 'Instrument Sans'; src: url('/fonts/InstrumentSans-Regular.ttf'); font-weight: 400; }
@font-face { font-family: 'Instrument Sans'; src: url('/fonts/InstrumentSans-Medium.ttf'); font-weight: 500; }
@font-face { font-family: 'Instrument Sans'; src: url('/fonts/InstrumentSans-SemiBold.ttf'); font-weight: 600; }
@font-face { font-family: 'Instrument Sans'; src: url('/fonts/InstrumentSans-Bold.ttf'); font-weight: 700; }

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --ink: #17181a;
  --secondary: #55565e;
  --tertiary: #83848c;
  --muted: #9a9ba3;
  --ghost: #c2c3ca;
  --border: #ececf0;
  --border-input: #e2e2e8;
  --border-input-hover: #c6c7cf;
  --hairline: #f0f0f3;
  --chip: #f0f0f3;
  --seg-bg: #efeff1;
  --hover-row: #fafafb;
  --oxblood: #6e1423;
  --oxblood-dark: #571019;
  --oxblood-soft: rgba(110, 20, 35, .07);
  --sent-fg: #a05c12;
  --sent-bg: #fbf1e2;
  --paid-fg: #256a3c;
  --paid-bg: #e6f2e9;
  --shadow-card: 0 1px 2px rgba(16, 17, 20, .04);
  --shadow-seg: 0 1px 2px rgba(16, 17, 20, .08);
  --shadow-doc: 0 8px 28px rgba(16, 17, 20, .12);
  --sans: 'Instrument Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }

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

.shell { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 212px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 20px; text-decoration: none; color: var(--ink); }
.brand img { width: 28px; height: auto; }
.brand span { font-weight: 600; font-size: 15px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .sidebar-foot a, .nav-logout {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--secondary);
  padding: 9px 12px;
  border-radius: 8px;
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
}
.sidebar nav a:hover, .sidebar-foot a:hover, .nav-logout:hover { background: #f4f4f6; color: var(--ink); }
.sidebar nav a.active, .sidebar-foot a.active { color: var(--oxblood); background: var(--oxblood-soft); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-foot form { margin: 0; }
.nav-logout { color: var(--muted); }

main { flex: 1; padding: 30px 36px; min-width: 0; }

/* ---------- page head ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 25px; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { font-size: 13.5px; color: var(--tertiary); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; align-items: center; }

/* ---------- buttons ---------- */
.btn-primary, .btn-secondary {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  border: 1px solid transparent;
  color: var(--ink);
}
.btn-primary { background: var(--oxblood); color: #fff; }
.btn-primary:hover { background: var(--oxblood-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border-input); }
.btn-secondary:hover { border-color: var(--border-input-hover); }
.btn-dashed {
  font-family: var(--sans); font-size: 12.5px; font-weight: 500; color: var(--secondary);
  border: 1px dashed #d5d5dc; border-radius: 9px; padding: 8px 14px; background: none; cursor: pointer;
}
.btn-dashed:hover { border-color: var(--muted); color: var(--ink); }
.text-link { color: var(--oxblood); font-weight: 600; font-size: 13px; text-decoration: none; cursor: pointer; background: none; border: none; font-family: var(--sans); padding: 0; }
.text-link:hover { text-decoration: underline; }
.link-danger { background: none; border: none; color: var(--oxblood); cursor: pointer; font-size: 13px; font-weight: 600; padding: 0; font-family: var(--sans); }
.link-danger:hover { text-decoration: underline; }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; background: var(--seg-bg); border-radius: 9px; padding: 3px; font-size: 13px; font-weight: 600; }
.seg > * {
  padding: 6px 14px; border-radius: 7px; color: var(--tertiary); cursor: pointer;
  background: none; border: none; font: inherit; text-decoration: none;
}
.seg > *:hover { color: var(--ink); }
.seg > .on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-seg); }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
}
.card-pad { padding: 17px 22px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--hairline);
}
.card-head .t { font-size: 15px; font-weight: 600; }
.card-head .s { font-size: 12.5px; color: var(--tertiary); }
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 22px; background: var(--hover-row); border-radius: 0 0 13px 13px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--tertiary);
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 19px 22px; box-shadow: var(--shadow-card); }
.stat .label { font-size: 13px; font-weight: 500; color: var(--tertiary); }
.stat .value { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 6px; }
.stat .value .cents { color: #b3b4bc; }
.stat .value.accent { color: var(--oxblood); }
.stat .value.accent .cents { color: inherit; opacity: .45; }
.stat .value .unit { font-size: 16px; color: var(--tertiary); font-weight: 500; }
.stat .sub { font-size: 12.5px; color: var(--tertiary); margin-top: 5px; }

/* ---------- monthly chart (dashboard) ---------- */
.mchart { display: flex; gap: 10px; align-items: flex-end; padding: 20px 22px 16px; }
.mchart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; min-width: 0; }
.mchart .val { font-size: 11px; font-weight: 600; color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mchart .bar { width: 100%; max-width: 34px; background: var(--oxblood); border-radius: 3px 3px 0 0; }
.mchart .bar.stub { background: var(--border); }
.mchart .m { font-size: 9.5px; font-weight: 600; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }

/* ---------- list rows ---------- */
.rows { display: flex; flex-direction: column; }
.row, .row-head {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 22px; border-bottom: 1px solid var(--hairline); font-size: 14px;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--hover-row); }
.row-head {
  padding: 11px 22px; border-bottom: 1px solid var(--border);
  font-size: 11.5px; font-weight: 600; letter-spacing: .06em; color: var(--muted); text-transform: uppercase;
}
.row-head:hover { background: none; }
.c-no { width: 52px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--tertiary); }
.c-desc { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-date { width: 80px; font-size: 12.5px; color: var(--tertiary); }
.c-type { width: 64px; font-size: 12px; color: var(--secondary); }
.c-cat { width: 96px; font-size: 12px; color: var(--secondary); }
.c-receipt { width: 70px; font-size: 12.5px; }
.c-receipt a { color: var(--oxblood); font-weight: 500; text-decoration: none; }
.c-receipt a:hover { text-decoration: underline; }
.c-receipt .none { color: var(--ghost); }
.c-status { width: 130px; }
.c-status-mid { width: 64px; text-align: center; }
.c-amount { width: 92px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.c-date.wide { width: 88px; }
.c-amount.slim { width: 84px; }
.c-action { width: 130px; text-align: right; font-size: 12.5px; }
.c-action .quiet { color: var(--muted); }
.row.dim { color: var(--muted); }
.row.dim .c-desc, .row.dim .c-amount { color: var(--muted); }

/* ---------- pills ---------- */
.pill {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--secondary);
  border: none; cursor: default; font-family: var(--sans); white-space: nowrap;
}
button.pill { cursor: pointer; }
button.pill:hover { filter: brightness(.96); }
.pill-sent, .pill-aging, .pill-warn { background: var(--sent-bg); color: var(--sent-fg); }
.pill-paid, .pill-claimed { background: var(--paid-bg); color: var(--paid-fg); }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 500; color: var(--secondary); }
.hint { font-weight: 400; color: var(--muted); font-size: 11.5px; line-height: 1.45; }
input, select, textarea {
  font-family: var(--sans); font-size: 13.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border-input); border-radius: 8px; padding: 8px 10px;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-input-hover); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--oxblood); outline-offset: -1px; border-color: var(--oxblood); }
input:disabled { background: var(--hairline); color: var(--muted); }
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-grid .span2 { grid-column: span 2; }
.quick-add { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.quick-add label { flex: 0 1 auto; }
.quick-add .grow { flex: 1 1 140px; }
.inline-form { display: inline; margin: 0; }

.error { background: var(--oxblood-soft); color: var(--oxblood); border: 1px solid #e8ccd1; border-radius: 9px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.success { background: var(--paid-bg); color: var(--paid-fg); border: 1px solid #cfe4d5; border-radius: 9px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.warn { background: var(--sent-bg); color: var(--sent-fg); border: 1px solid #ecd7b6; border-radius: 9px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; }
.empty { color: var(--muted); padding: 20px 22px; font-size: 13.5px; }

/* ---------- editor (2a): top bar + rails + live document ---------- */
.editor-bar {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 24px; margin: -30px -36px 24px; position: sticky; top: 0; z-index: 5;
}
.editor-bar .back { color: var(--tertiary); font-size: 13.5px; text-decoration: none; }
.editor-bar .back:hover { color: var(--ink); }
.editor-bar .doc-title { font-size: 17px; font-weight: 600; }
.editor-bar .spacer { margin-left: auto; }
.saved-note { font-size: 12.5px; color: var(--muted); }

.editor-layout { display: flex; gap: 24px; align-items: flex-start; }
.editor-rail { width: 268px; flex: none; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 92px; }
.rail-card { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 17px 19px; box-shadow: var(--shadow-card); }
.rail-card .rc-title { font-size: 13px; font-weight: 600; margin-bottom: 13px; }
.rail-card .stack { display: flex; flex-direction: column; gap: 11px; }
.rail-card input.invalid { border-color: var(--oxblood); background: var(--oxblood-soft); }
.rail-add {
  display: block; width: 100%; background: var(--oxblood); color: #fff; font-weight: 600; font-size: 13.5px;
  padding: 9px 0; border: none; border-radius: 9px; text-align: center; margin-top: 13px; cursor: pointer; font-family: var(--sans);
}
.rail-add:hover { background: var(--oxblood-dark); }
.rail-dashed {
  display: block; width: 100%; border: 1px dashed #d5d5dc; color: var(--secondary); font-weight: 500; font-size: 12.5px;
  padding: 8px 0; border-radius: 9px; text-align: center; margin-top: 9px; cursor: pointer; background: none; font-family: var(--sans);
}
.rail-dashed:hover { border-color: var(--muted); color: var(--ink); }
.running-total { display: flex; justify-content: space-between; align-items: baseline; padding: 15px 19px; }
.running-total .rt-label { font-size: 12.5px; font-weight: 500; color: var(--secondary); }
.running-total .rt-value { font-size: 19px; font-weight: 700; color: var(--oxblood); font-variant-numeric: tabular-nums; }

.doc-stage { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 11px; min-width: 0; }
.doc-page { position: relative; width: 612px; max-width: 100%; background: var(--surface); border-radius: 4px; box-shadow: var(--shadow-doc); }
.doc-ribbon {
  position: absolute; top: 22px; right: -13px; background: var(--chip); color: var(--secondary);
  font-weight: 700; font-size: 10.5px; letter-spacing: .12em; padding: 5px 12px; border-radius: 5px;
  transform: rotate(3deg); box-shadow: 0 1px 3px rgba(16, 17, 20, .12);
}
.doc-hint { font-size: 12.5px; color: var(--muted); }

/* the document itself */
.doc-body { display: flex; flex-direction: column; min-height: 792px; padding: 48px 52px 36px; font-size: 11px; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; }
.doc-biz { display: flex; align-items: center; gap: 11px; }
.doc-biz img { width: 34px; height: auto; }
.doc-biz .b-name { font-weight: 600; font-size: 13.5px; }
.doc-biz .b-loc { font-size: 10.5px; color: var(--tertiary); }
.doc-no { text-align: right; }
.doc-no .lab { font-size: 10px; font-weight: 600; letter-spacing: .14em; color: var(--tertiary); }
.doc-no .num { font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 2px; }

.doc-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 14px;
  margin-top: 30px; padding: 15px 18px; background: #f8f8f9; border-radius: 10px;
}
.doc-meta .m-label { font-size: 9.5px; font-weight: 600; letter-spacing: .08em; color: var(--muted); }
.doc-meta .m-value { font-size: 11.5px; font-weight: 500; margin-top: 3px; }
.doc-meta .m-value.due { color: var(--oxblood); }
.doc-meta .m-value.code { font-size: 10px; word-break: break-all; }

.doc-table { width: 100%; border-collapse: collapse; margin-top: 26px; font-size: 11px; }
.doc-table th {
  text-align: left; font-size: 9.5px; letter-spacing: .08em; color: var(--muted); font-weight: 600;
  padding: 0 0 8px; border-bottom: 1px solid var(--ink);
}
.doc-table th.num, .doc-table td.num { text-align: right; }
.doc-table td { padding: 7.5px 0; border-bottom: 1px solid var(--hairline); font-variant-numeric: tabular-nums; vertical-align: baseline; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table td.rate { color: var(--muted); }
.doc-table td.amount { font-weight: 600; }
.doc-table td.del { width: 24px; text-align: right; }
.doc-table td.del button { background: none; border: none; color: var(--oxblood); cursor: pointer; font-weight: 600; font-size: 11px; padding: 0 0 0 6px; visibility: hidden; }
.doc-table tr:hover td.del button, .doc-table tr:focus-within td.del button { visibility: visible; }
.doc-table tr:focus-within td { background: #fbf7f7; }

[data-edit] {
  border-bottom: 1px dashed #c9c9d1; cursor: text; min-width: 18px; display: inline-block; outline: none;
}
[data-edit]:focus {
  background: #fff; border-bottom-color: transparent; border-radius: 6px;
  outline: 1.5px solid var(--oxblood); box-shadow: 0 0 0 3px rgba(110, 20, 35, .1);
  padding: 2px 8px; margin: -2px -8px;
}
[data-edit]:empty::before { content: '…'; color: var(--ghost); }

.doc-totals { display: flex; justify-content: flex-end; margin-top: 20px; }
.doc-totals .panel { background: #faf6f6; border: 1px solid #f0e2e4; border-radius: 12px; padding: 15px 20px; min-width: 210px; }
.doc-totals .sub { display: flex; justify-content: space-between; font-size: 11px; color: var(--tertiary); }
.doc-totals .sub b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.doc-totals .grand { display: flex; justify-content: space-between; align-items: baseline; margin-top: 9px; padding-top: 9px; border-top: 1px solid #f0e2e4; }
.doc-totals .grand .lab { font-size: 11px; font-weight: 600; }
.doc-totals .grand .val { font-size: 22px; font-weight: 700; color: var(--oxblood); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.doc-notes { margin-top: 18px; font-size: 10px; color: var(--secondary); white-space: pre-line; }
.doc-foot {
  margin-top: auto; padding-top: 22px; border-top: 1px solid var(--hairline);
  display: flex; justify-content: space-between; font-size: 9.5px; color: var(--muted);
}
.doc-foot b { color: var(--ink); font-weight: 500; }

/* ---------- search ---------- */
.search {
  background: var(--surface); border: 1px solid var(--border-input); border-radius: 9px;
  padding: 8px 14px; font-size: 13.5px; width: 220px;
}
.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.toolbar .search { margin-left: auto; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.role-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); margin: 0; font-family: var(--sans); color: var(--ink); }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 42px; width: min(380px, 92vw); text-align: center; box-shadow: 0 8px 28px rgba(16, 17, 20, .08);
}
.login-logo { width: 64px; height: auto; }
.login-title { font-size: 19px; font-weight: 600; margin: 14px 0 2px; }
.login-title .co { font-weight: 400; color: var(--tertiary); }
.login-sub { color: var(--tertiary); margin: 0 0 22px; font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card .btn-primary { margin-top: 6px; width: 100%; text-align: center; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; gap: 4px; overflow-x: auto; }
  .brand { padding: 0 8px 0 0; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; border: none; padding: 0; flex-direction: row; }
  main { padding: 20px 16px; }
  .editor-bar { margin: -20px -16px 20px; flex-wrap: wrap; }
  .editor-layout { flex-direction: column; }
  .editor-rail { width: 100%; position: static; }
  .doc-body { padding: 28px 24px 24px; min-height: 0; }
  .c-date, .c-type, .c-cat { display: none; }
}
