:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #faf7f3;
  --ink: #2a1c13;
  --muted: #7b6b5e;
  --line: #e7ded3;
  --brand: #6b3e26;
  --brand-ink: #ffffff;
  --brand-soft: #f1e6dc;
  --alert: #e8590c;
  --alert-soft: #fff1e6;
  --ok: #2f7d4f;
  --ok-soft: #e5f4ea;
  --warn: #a86b00;
  --warn-soft: #fff6dd;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --info: #2a5d8f;
  --info-soft: #e7f0f9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(42, 28, 19, .06), 0 4px 16px rgba(42, 28, 19, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--line); background: var(--surface);
  padding: .5rem .9rem; border-radius: 9px; cursor: pointer; text-decoration: none;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; border-radius: 7px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--brand); text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
.field { margin-bottom: .8rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=month], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.fgrid { display: grid; gap: 0 .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; font-size: .95rem; }
.check input { width: 18px; height: 18px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .75rem; margin: 0 0 .8rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }

/* Cards and tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-bottom: .75rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.tile .k { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.tile .v { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; }
.tile.alert { border-color: var(--alert); background: var(--alert-soft); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.low td { background: var(--danger-soft); }
.empty { padding: 1.25rem; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; }

.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.grey { background: #eee8e2; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.login-box { width: 100%; max-width: 760px; }
.brand-big { text-align: center; margin-bottom: 1.25rem; }
.brand-big .logo { font-size: 2.2rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .6rem .9rem; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.profiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.profile { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; cursor: pointer; display: flex; gap: .75rem; align-items: center; }
.profile:hover { border-color: var(--brand); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }

/* Shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: #2a1c13; color: #f1e6dc; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { font-weight: 800; font-size: 1.05rem; padding: .25rem .5rem 1rem; display: flex; gap: .5rem; align-items: center; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { display: flex; justify-content: space-between; align-items: center; background: none; border: 0; color: inherit; text-align: left; padding: .55rem .65rem; border-radius: 8px; cursor: pointer; font-weight: 500; opacity: .85; }
.nav button:hover { background: rgba(255,255,255,.07); opacity: 1; }
.nav button.on { background: rgba(255,255,255,.14); opacity: 1; font-weight: 700; }
.nav .count { background: var(--alert); color: #fff; border-radius: 999px; font-size: .72rem; font-weight: 800; padding: .05rem .45rem; min-width: 1.4rem; text-align: center; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top h1 { margin: 0; }
.top-r { display: flex; align-items: center; gap: .6rem; }
.me { text-align: right; line-height: 1.2; }
.me b { display: block; font-size: .9rem; }
.me span { font-size: .78rem; color: var(--muted); }
.content { padding: 1.25rem 1.5rem 3rem; max-width: 1280px; width: 100%; }

/* Notifications: made deliberately loud */
.notif-wrap { position: relative; }
.bell {
  position: relative; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  display: grid; place-items: center;
}
.bell svg { width: 20px; height: 20px; }
.bell.has-unread { background: var(--alert); border-color: var(--alert); color: #fff; animation: ring 2.4s ease-in-out infinite; }
.bell .pill {
  position: absolute; top: -6px; right: -8px; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; background: #c92a2a; color: #fff; font-size: .75rem; font-weight: 800;
  display: grid; place-items: center; border: 2px solid #fff;
}
@keyframes ring { 0%, 100% { box-shadow: 0 0 0 0 rgba(232, 89, 12, .55); } 50% { box-shadow: 0 0 0 8px rgba(232, 89, 12, 0); } }
@media (prefers-reduced-motion: reduce) { .bell.has-unread { animation: none; } }
.notif-panel {
  position: absolute; right: 0; top: 50px; width: min(400px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 40px rgba(0,0,0,.18); z-index: 50;
}
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.notif-section { padding: .4rem 1rem; font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); }
.notif { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); padding: .7rem 1rem .7rem 1rem; cursor: pointer; color: var(--muted); }
.notif:hover { background: var(--surface-2); }
.notif .when { font-size: .75rem; display: block; margin-top: .2rem; }
.notif.unread { background: var(--alert-soft); color: var(--ink); font-weight: 600; border-left: 5px solid var(--alert); padding-left: calc(1rem - 5px); }
.notif.unread:hover { background: #ffe6d3; }
.new-chip { display: inline-block; background: var(--alert); color: #fff; font-size: .65rem; font-weight: 800; letter-spacing: .05em; padding: .05rem .4rem; border-radius: 4px; margin-right: .4rem; vertical-align: 1px; }
.unread-banner {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  margin: 1rem 1.5rem 0; padding: .7rem 1rem; border-radius: 10px;
  background: var(--alert); color: #fff; font-weight: 600;
}
.unread-banner .btn { background: #fff; color: var(--alert); border-color: #fff; }

/* Toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: center; width: calc(100% - 32px); max-width: 460px; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); width: 100%; }
.toast.alert { background: var(--alert); font-weight: 600; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(30, 20, 12, .45); display: grid; place-items: center; padding: 1rem; z-index: 60; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; padding: 1.25rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.x { background: none; border: 0; font-size: 1.5rem; cursor: pointer; line-height: 1; color: var(--muted); }

/* Ideas */
.idea-card { cursor: pointer; }
.idea-card:hover { border-color: var(--brand); }
.post { border: 1px solid var(--line); border-radius: 10px; padding: .75rem; background: var(--surface-2); }
.post + .post { margin-top: .6rem; }
.post .meta { font-size: .8rem; color: var(--muted); margin-bottom: .3rem; }
.post img, .post video { max-width: 100%; max-height: 360px; border-radius: 8px; display: block; margin-top: .5rem; }
.post .text { white-space: pre-wrap; word-break: break-word; }
.task { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.task input { width: 18px; height: 18px; margin-top: .15rem; flex: none; }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.t-meta { font-size: .8rem; color: var(--muted); }

/* Status tracker */
.tracker { display: flex; gap: 0; margin: .6rem 0 .2rem; }
.step { flex: 1; text-align: center; position: relative; font-size: .78rem; color: var(--muted); }
.step::before { content: ""; position: absolute; top: 9px; left: -50%; width: 100%; height: 3px; background: var(--line); z-index: 0; }
.step:first-child::before { display: none; }
.step .dot { width: 20px; height: 20px; border-radius: 50%; background: var(--line); margin: 0 auto .25rem; position: relative; z-index: 1; display: grid; place-items: center; color: #fff; font-size: .7rem; font-weight: 800; }
.step.done { color: var(--ink); font-weight: 600; }
.step.done .dot, .step.done::before { background: var(--ok); }
.step.current .dot { background: var(--alert); box-shadow: 0 0 0 4px var(--alert-soft); }

/* Kanban */
.board { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
.col { background: #efe7de; border-radius: var(--radius); padding: .75rem; }
.col h3 { display: flex; justify-content: space-between; font-size: .9rem; }
.ocard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .7rem; margin-top: .6rem; }
.ocard ul { margin: .35rem 0; padding-left: 1.1rem; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: .4rem; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 110px; gap: .6rem; align-items: center; font-size: .88rem; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 18px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { background: var(--brand); height: 100%; border-radius: 6px 0 0 6px; }
.vbars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 1.2rem; border-bottom: 1px solid var(--line); }
.vbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.vbar .fill { width: 100%; max-width: 46px; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 2px; }
.vbar .val { font-size: .68rem; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.vlabels { display: flex; gap: 6px; }
.vlabels span { flex: 1; text-align: center; font-size: .75rem; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: .4rem .75rem; cursor: pointer; font-size: .88rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; }

/* CEO overview */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; background: linear-gradient(135deg, #2a1c13, #6b3e26); color: #fff; border: 0; }
.hero .k { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; opacity: .8; font-weight: 700; }
.hero-v { font-size: 2.4rem; font-weight: 800; line-height: 1.1; margin: .2rem 0 .4rem; }
.hero .muted { color: rgba(255,255,255,.8); }
.hero-side { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.hero-side b { font-size: 1.15rem; }
.streams { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stream, .area { text-align: left; cursor: pointer; font: inherit; color: inherit; width: 100%; }
.stream:hover, .area:hover { border-color: var(--brand); }
.stream .k { font-size: .8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.stream .v { font-size: 1.35rem; font-weight: 800; margin-top: .15rem; }
.areas { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.area-rows { margin-top: .6rem; display: flex; flex-direction: column; gap: .3rem; }
.warn-text { color: var(--alert); }
table.entry td { padding: .3rem .4rem; }
table.entry input { min-width: 90px; }

/* Client portal */
.client-top { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.client-main { max-width: 980px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.bill-total { font-size: 1.6rem; font-weight: 800; }
.paybox { text-align: center; padding: 2rem 1rem; }

/* Invoice */
.invoice { font-size: .92rem; }
.invoice .inv-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--ink); padding-bottom: .75rem; margin-bottom: .75rem; }

@media print {
  body * { visibility: hidden; }
  .invoice, .invoice * { visibility: visible; }
  .invoice { position: absolute; left: 0; top: 0; width: 100%; }
  .no-print { display: none !important; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: .5rem; }
  .side .brand { padding: .25rem .5rem .5rem; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav button { white-space: nowrap; gap: .4rem; }
  .top { padding: .6rem 1rem; }
  .content { padding: 1rem 1rem 3rem; }
  .unread-banner { margin: .75rem 1rem 0; }
  .me { display: none; }
  .bar-row { grid-template-columns: 100px 1fr 90px; }
  .client-top { padding: .6rem 1rem; }
}

/* while a change is being saved */
body.busy, body.busy * { cursor: progress !important; }
