/* Cashmi web admin
   A group cash book: cool paper, lagoon green ink, amber for "waiting",
   red only for money that is late. Figures use tabular numerals. */

:root {
  --paper: #f3f6f5;
  --surface: #ffffff;
  --ink: #16302a;
  --ink-2: #4a625c;
  --ink-3: #6f8580;
  --line: #d6e1dd;
  --line-2: #e7eeeb;
  --lagoon: #0f6e5c;
  --lagoon-deep: #0a5345;
  --lagoon-tint: #e2f0ec;
  --amber: #9a6208;
  --amber-tint: #fbf0d9;
  --red: #b42318;
  --red-tint: #fdeceb;
  --focus: #2563c9;

  --font: "IBM Plex Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
  --side: 236px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}
a { color: var(--lagoon); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--lagoon-deep); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; max-width: 72ch; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--ink-3); }
.small { font-size: 0.86rem; }
.nowrap { white-space: nowrap; }

/* ---------- shell ---------- */
.shell {
  display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh;
  background: linear-gradient(to right, var(--lagoon-deep) var(--side), transparent var(--side));
}
.side {
  background: var(--lagoon-deep);
  color: #e5f2ee;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; font-size: 1.05rem; }
.brand svg { flex: none; }
.side .group-name { font-size: 0.86rem; color: #b9d8cf; margin-top: -10px; padding-left: 38px; }
.side .group-name a { color: #b9d8cf; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  color: #d3e8e1; text-decoration: none; padding: 8px 10px; border-radius: var(--r-sm);
  font-size: 0.95rem;
}
.nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav a[aria-current="page"] { background: #fff; color: var(--lagoon-deep); font-weight: 600; }
.nav .count { background: var(--amber-tint); color: var(--amber); border-radius: 20px; padding: 0 7px; font-size: 0.78rem; font-weight: 600; }
.side .foot { margin-top: auto; font-size: 0.84rem; color: #a9cbc1; display: flex; flex-direction: column; gap: 6px; }
.side .foot a, .side .foot button { color: #d3e8e1; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--lagoon); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.main { padding: 28px 36px 64px; min-width: 0; }
.wrap { max-width: 1120px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { margin: 6px 0 0; color: var(--ink-2); }
.crumb { font-size: 0.88rem; margin-bottom: 6px; display: inline-block; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; background: none; }
  .side { position: static; height: auto; padding: 12px 16px; gap: 10px; }
  .side .group-name { padding-left: 38px; margin-top: -6px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; margin: 0 -16px; padding: 0 16px 4px; scrollbar-width: none; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side .foot { flex-direction: row; justify-content: space-between; margin-top: 0; }
  .main { padding: 20px 16px 48px; }
  h1 { font-size: 1.35rem; }
}

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.panel > .panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.panel > .panel-body { padding: 16px 18px; }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

/* The balances strip: one band of figures, not a grid of cards */
.strip { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
.strip > div { flex: 1 1 0; min-width: 150px; padding: 14px 18px; border-left: 1px solid var(--line-2); }
.strip > div:first-child { border-left: 0; }
.strip .label { font-size: 0.84rem; color: var(--ink-2); }
.strip .fig { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.strip .sub { font-size: 0.8rem; color: var(--ink-3); }
.strip .bad .fig { color: var(--red); }
.strip a { color: inherit; text-decoration: none; display: block; }
.strip a:hover .label { text-decoration: underline; }

/* ---------- turn track (the rotation, start to finish) ---------- */
.track-wrap { overflow-x: auto; padding: 6px 2px 4px; }
.track { list-style: none; margin: 0; padding: 0; display: flex; min-width: min-content; }
.stop { flex: 0 0 104px; position: relative; text-align: center; padding-top: 2px; }
.stop::before { /* rail to the previous stop */
  content: ""; position: absolute; top: 25px; right: 50%; width: 100%; height: 3px; background: var(--line);
}
.stop:first-child::before { display: none; }
.stop.done::before, .stop.now::before { background: var(--lagoon); }
.stop .dot {
  position: relative; z-index: 1; width: 48px; height: 48px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 0.95rem;
  background: var(--surface); border: 2px solid var(--line); color: var(--ink-2);
  text-decoration: none;
}
.stop.done .dot { background: var(--lagoon); border-color: var(--lagoon); color: #fff; }
.stop.now .dot { width: 56px; height: 56px; margin-top: -4px; border: 3px solid var(--amber); background: var(--amber-tint); color: var(--amber); }
.stop .who { margin-top: 8px; font-size: 0.86rem; font-weight: 500; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop .when { font-size: 0.78rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.stop.now .when { color: var(--amber); font-weight: 600; }
.stop.mine .who { color: var(--lagoon); font-weight: 600; }
a.dot:hover { box-shadow: 0 0 0 4px var(--lagoon-tint); }

.now-card { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; }
.now-card .big { font-size: 1.5rem; font-weight: 600; }
@media (max-width: 640px) { .now-card { grid-template-columns: 1fr; } }

.bar { height: 8px; border-radius: 8px; background: var(--line-2); overflow: hidden; margin: 10px 0 6px; }
.bar > span { display: block; height: 100%; background: var(--lagoon); border-radius: 8px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line-2); }
th { font-size: 0.84rem; font-weight: 600; color: var(--ink-2); background: #f8fbfa; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
td.sub { color: var(--ink-3); font-size: 0.86rem; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
.row-link { color: inherit; text-decoration: none; font-weight: 500; }
.row-link:hover { color: var(--lagoon); text-decoration: underline; }
.amt.pos { color: var(--lagoon); }
.amt.neg { color: var(--red); }
tr.is-paid td { color: var(--ink-2); }
.empty { padding: 34px 18px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 1.02rem; margin-bottom: 4px; }

/* ---------- tags ---------- */
.tag { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.tag-ok { background: var(--lagoon-tint); color: var(--lagoon-deep); }
.tag-wait { background: var(--amber-tint); color: var(--amber); }
.tag-bad { background: var(--red-tint); color: var(--red); }
.tag-muted { background: var(--line-2); color: var(--ink-2); }

/* ---------- tabs / filters ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a[aria-current="page"] { color: var(--lagoon-deep); border-bottom-color: var(--lagoon); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 20px; text-decoration: none; color: var(--ink-2); font-size: 0.9rem; background: var(--surface); }
.chip[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- forms & buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 40px; border-radius: var(--r-sm);
  border: 1px solid var(--lagoon); background: var(--lagoon); color: #fff;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--lagoon-deep); border-color: var(--lagoon-deep); color: #fff; }
.btn.secondary { background: var(--surface); color: var(--lagoon-deep); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--lagoon); background: var(--lagoon-tint); }
.btn.danger { background: var(--surface); color: var(--red); border-color: #efc4c0; }
.btn.danger:hover { background: var(--red-tint); }
.btn.small { padding: 4px 11px; min-height: 32px; font-size: 0.88rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-weight: 500; font-size: 0.92rem; }
.field .help { font-size: 0.82rem; color: var(--ink-3); }
.field .err { font-size: 0.84rem; color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #c3d2cd; border-radius: var(--r-sm);
  padding: 8px 10px; min-height: 40px; width: 100%;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input.amount { max-width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 18px; height: 18px; accent-color: var(--lagoon); }
.inline-form { display: inline; }
fieldset { border: 0; padding: 0; margin: 0; }

/* ---------- messages ---------- */
.flash { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; }
.flash li { padding: 10px 14px; border-radius: var(--r-sm); border-left: 4px solid var(--lagoon); background: var(--lagoon-tint); }
.flash li.error { border-color: var(--red); background: var(--red-tint); color: #7a1a12; }

.note { padding: 12px 14px; border-radius: var(--r-sm); background: var(--amber-tint); color: #5f3f06; font-size: 0.92rem; }
.note.calm { background: var(--lagoon-tint); color: var(--lagoon-deep); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.facts dt { color: var(--ink-2); }
dl.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
dl.facts dd.strong { font-weight: 600; }

/* ---------- plain pages (sign in, pick group) ---------- */
.plain { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.plain .box { width: 100%; max-width: 420px; }
.plain .brand { color: var(--lagoon-deep); margin-bottom: 18px; font-size: 1.25rem; }
.plain.wide .box { max-width: 760px; }

@media print {
  .side, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  body { background: #fff; font-size: 12px; }
  .panel, .strip { border-color: #bbb; }
  a { color: inherit; text-decoration: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .stop.now .dot { animation: settle 600ms ease-out 1; }
  @keyframes settle { from { transform: scale(0.85); } to { transform: scale(1); } }
}

/* Phones: figures wrap into two columns (kept last so it wins over the base rules) */
@media (max-width: 860px) {
  .strip { display: grid; grid-template-columns: 1fr 1fr; overflow: visible; }
  .strip > div { min-width: 0; border-left: 0; border-top: 1px solid var(--line-2); }
  .strip > div:nth-child(even) { border-left: 1px solid var(--line-2); }
  .strip > div:nth-child(-n+2) { border-top: 0; }
  .strip > div[style] { grid-column: 1 / -1; border-left: 0; }
  .strip .fig { font-size: 1.15rem; }
}

/* ---------- groups switcher & cards ---------- */
.nav a.sub-item { padding-left: 24px; font-size: 0.9rem; color: #b9d8cf; }
.nav a.sub-item[aria-current="page"] { color: var(--lagoon-deep); }
.count { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 6px; border-radius: 20px; background: var(--amber); color: #fff; font-size: 0.75rem; font-weight: 600; line-height: 18px; text-align: center; }
.nav a .count { background: #e0a02a; color: #3a2600; }
.switcher { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 16px; padding-bottom: 2px; scrollbar-width: none; }
.switcher a { flex: none; padding: 7px 14px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 0.92rem; }
.switcher a[aria-current="page"] { background: var(--lagoon); border-color: var(--lagoon); color: #fff; }
.switcher a[aria-current="page"] .muted { color: #cfe6df; }
.group-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 10px; }
.gc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.gc-line { margin: 4px 0; }
tr.is-unread td { background: #fbfdfc; }
tr.is-unread .row-link { font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- chat (messenger style) ---------- */
.chat { display: flex; flex-direction: column; height: min(72vh, 680px); min-height: 380px; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); background: var(--surface); }
.chat-head .faces { display: flex; flex: none; }
.chat-head .faces .avatar { width: 34px; height: 34px; font-size: 0.78rem; border: 2px solid var(--surface); margin-left: -10px; }
.chat-head .faces .avatar:first-child { margin-left: 0; }
.chat-head .faces .more { background: var(--line-2); color: var(--ink-2); }
.chat-title { min-width: 0; }
.chat-title .name { font-weight: 600; line-height: 1.25; }
.chat-title .sub { font-size: 0.8rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar { flex: none; width: 30px; height: 30px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em; color: #fff; }
.tone-0 { background: #0f6e5c; } .tone-1 { background: #9a6208; } .tone-2 { background: #2f5d8a; }
.tone-3 { background: #7a3f6b; } .tone-4 { background: #4d6b2a; } .tone-5 { background: #a2462a; }

.msgs { list-style: none; margin: 0; padding: 14px 14px 10px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; background: var(--surface); overscroll-behavior: contain; }
.msgs .day { align-self: stretch; text-align: center; font-size: 0.75rem; font-weight: 500; color: var(--ink-3); margin: 14px 0 6px; }
.msgs .none { align-self: center; margin: auto; color: var(--ink-2); text-align: center; max-width: 36ch; }

.msg { display: flex; align-items: flex-end; gap: 8px; max-width: min(80%, 560px); align-self: flex-start; }
.msg.start { margin-top: 8px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { visibility: hidden; }
.msg.end .avatar { visibility: visible; }
.msg .stack { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.msg.mine .stack { align-items: flex-end; }
.msg .from { display: none; font-size: 0.75rem; color: var(--ink-3); margin: 0 0 2px 12px; }
.msg.start .from { display: block; }
.msg .role { color: var(--amber); font-weight: 500; }
.msg .bubble { padding: 8px 13px; border-radius: 18px; background: #eaf0ee; color: var(--ink); overflow-wrap: anywhere; line-height: 1.4; }
.msg:not(.start) .bubble { border-top-left-radius: 5px; }
.msg:not(.end) .bubble { border-bottom-left-radius: 5px; }
.msg.mine .bubble { background: var(--lagoon); color: #fff; border-radius: 18px; }
.msg.mine:not(.start) .bubble { border-top-right-radius: 5px; }
.msg.mine:not(.end) .bubble { border-bottom-right-radius: 5px; }
.msg.mine .bubble a { color: #fff; }
.msg.jumbo .bubble { background: none; padding: 0 2px; font-size: 2.2rem; line-height: 1.15; }
.msg .at { display: none; font-size: 0.7rem; color: var(--ink-3); margin: 3px 12px 2px; }
.msg.end .at { display: block; }
.msg.sending .bubble { opacity: 0.55; }

.compose { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line-2); align-items: flex-end; background: var(--surface); }
.compose textarea { flex: 1; min-height: 40px; max-height: 140px; resize: none; border-radius: 20px; padding: 9px 16px; background: #eef3f1; border: 1px solid transparent; line-height: 1.4; font: inherit; }
.compose textarea:focus { background: var(--surface); border-color: var(--line); }
.compose .send { flex: none; width: 44px; height: 40px; border-radius: 20px; border: 0; background: var(--lagoon); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.compose .send:hover { background: var(--lagoon-deep); }
.compose .send:disabled { background: var(--line); color: var(--ink-3); cursor: default; }
@media (max-width: 860px) { .chat { height: calc(100vh - 16px); height: calc(100dvh - 16px); min-height: 340px; scroll-margin-top: 8px; } .msg { max-width: 88%; } }

@media (max-width: 640px) {
  th, td { padding: 8px 10px; }
  .msgs { padding: 12px; }
}
