:root {
  --ink: #0f1b2d;
  --ink-2: #44526a;
  --muted: #6b778c;
  --line: #e3e8ef;
  --bg: #f5f7fa;
  --card: #ffffff;
  --brand: #1c617f;
  --brand-2: #237aa0;
  --accent: #2dfffe;
  --danger: #c2372f;
  --ok: #157a4a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px rgba(15, 27, 45, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .25rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 1.25rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
[hidden] { display: none !important; }

/* ── brand ── */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--brand); }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 2rem; height: 2rem; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff; font-size: .8rem; letter-spacing: .02em;
}

/* ── forms ── */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .9rem; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: .35rem;
  font: inherit; font-weight: 400; color: var(--ink);
  padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 9px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(28, 97, 127, .18);
}
input[type=file] { padding: .5rem; background: var(--bg); }
textarea { resize: vertical; }
.hint { font-size: .8rem; color: var(--muted); margin-top: -.4rem; }
.form-msg { min-height: 1.2em; font-size: .88rem; color: var(--danger); }
.form-msg[data-kind=ok] { color: var(--ok); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.actions { display: flex; justify-content: flex-end; gap: .5rem; }

/* ── buttons ── */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 9px; padding: .6rem 1rem;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #164f68; }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: #eef2f7; }
.btn.small { padding: .35rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.link { background: none; border: 0; color: var(--brand-2); font: inherit; font-size: .88rem; cursor: pointer; padding: .75rem 0 0; }
.link:hover { text-decoration: underline; }

/* ── auth pages ── */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background:
    radial-gradient(1200px 500px at 0% 0%, rgba(45, 200, 230, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(28, 97, 127, .14), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 2rem;
}
.auth-card .brand { margin-bottom: 1.5rem; }
.fine { font-size: .78rem; color: var(--muted); margin: 1.25rem 0 0; border-top: 1px solid var(--line); padding-top: 1rem; }

/* ── app shell ── */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .8rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.who { display: flex; align-items: center; gap: .6rem; font-size: .9rem; flex-wrap: wrap; justify-content: flex-end; }
.who #who-name { font-weight: 600; }
.container { max-width: 880px; margin: 0 auto; padding: 1.75rem 1rem 4rem; }
.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; }
.toolbar p { margin: 0; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.25rem 1.25rem .75rem; margin-bottom: 1.5rem;
}
.panel h2 { margin-bottom: 1rem; }

/* ── filters ── */
.filters { display: flex; gap: .4rem; margin-bottom: .75rem; }
.chip {
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-2);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ── ticket list ── */
.tickets { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.ticket {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.ticket:hover, .ticket:focus-visible { border-color: #c5d2e3; box-shadow: var(--shadow); outline: none; }
.ticket-main { display: grid; gap: .1rem; min-width: 0; }
.ticket .subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref { font-size: .75rem; font-weight: 700; color: var(--brand-2); letter-spacing: .03em; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }

.pill { font-size: .75rem; font-weight: 700; padding: .25rem .65rem; border-radius: 999px; white-space: nowrap; }
.pill.open { background: #e8f0fb; color: var(--brand-2); }
.pill.in-progress { background: #fff4de; color: #9a5b00; }
.pill.resolved { background: #e3f6ee; color: var(--ok); }

/* ── dialog ── */
dialog {
  width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  border: 0; border-radius: 16px; padding: 1.5rem; box-shadow: 0 24px 64px rgba(15, 27, 45, .25);
}
dialog::backdrop { background: rgba(15, 27, 45, .45); }
.dialog-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; margin: 1rem 0 0; padding: 1rem; background: var(--bg); border-radius: 10px; }
.meta dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.meta dd { margin: .15rem 0 0; font-weight: 600; font-size: .9rem; }
.desc { white-space: pre-wrap; word-break: break-word; }
.files { padding-left: 1.1rem; margin: 0; }
.files a { color: var(--brand-2); }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .75rem 1.1rem; border-radius: 10px;
  box-shadow: var(--shadow); font-size: .9rem; max-width: calc(100vw - 2rem);
}

@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .who #who-company { display: none; }
  .auth-card { padding: 1.5rem; }
}

/* ── conversation ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.thread { list-style: none; margin: 0 0 .75rem; padding: 0; display: grid; gap: .6rem; }
.msg { padding: .7rem .9rem; border-radius: 10px; max-width: 88%; border: 1px solid var(--line); }
.msg.team { background: #eef4fb; border-color: #d6e4f5; justify-self: start; }
.msg.mine { background: #fff; justify-self: end; }
.msg-head { display: flex; gap: .6rem; align-items: baseline; justify-content: space-between; font-size: .85rem; margin-bottom: .2rem; }
.msg-body { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
.reply textarea { margin-top: 0; }
.reply .actions { margin-bottom: 0; }

/* ── admin ── */
.container.wide { max-width: 1120px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
.tag {
  display: inline-block; margin-left: .4rem; padding: .05rem .45rem; border-radius: 6px;
  font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  background: #eef2f7; color: var(--ink-2); vertical-align: middle;
}
.tag.staff { background: #e6f6f3; color: #0c7a6d; }
.list-controls { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.list-controls input[type=search] { margin: 0; max-width: 320px; flex: 1 1 220px; }
.list-controls .filters { margin: 0; flex-wrap: wrap; }
.chip .count { opacity: .65; font-weight: 500; margin-left: .15rem; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.clients { width: 100%; border-collapse: collapse; font-size: .9rem; }
.clients th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; padding: .75rem 1rem; border-bottom: 1px solid var(--line); background: #fafbfd;
}
.clients td { padding: .8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.clients tr:last-child td { border-bottom: 0; }
.clients tr.is-off td { color: var(--muted); }
.clients .num { text-align: right; white-space: nowrap; }
.clients .email { overflow-wrap: anywhere; }
.client-name { font-weight: 600; }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; flex-wrap: nowrap; }
.actions-cell { white-space: nowrap; width: 1%; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdecea; border-color: #f3c4bf; }
.pill.active { background: #e3f6ee; color: var(--ok); }
.pill.invited { background: #fff4de; color: #9a5b00; }
.pill.deactivated { background: #eef0f3; color: var(--muted); }
#edit-dialog { width: min(440px, calc(100vw - 2rem)); }
#edit-dialog .dialog-head { margin-bottom: 1rem; }
#admin-link[hidden] { display: none !important; }

@media (max-width: 760px) {
  .grid-3 { grid-template-columns: 1fr; }
  .table-wrap { background: transparent; border: 0; }
  table.clients thead { display: none; }
  table.clients, .clients tbody, .clients tr, .clients td { display: block; width: 100%; }
  .clients tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .6rem; padding: .4rem 0; }
  .clients td { border: 0; padding: .35rem 1rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .clients td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left; }
  .clients td:first-child { display: block; text-align: left; }
  .clients td:first-child::before { display: none; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; }
  .actions-cell { width: 100%; }
}

/* ── logo ── */
.brand-logo { display: block; height: 32px; width: auto; border-radius: 6px; }
.brand-label { font-weight: 600; color: var(--ink-2); padding-left: .65rem; margin-left: .05rem; border-left: 1px solid var(--line); line-height: 1.4; }
.auth-card .brand { flex-direction: column; align-items: flex-start; gap: .75rem; margin: -2rem -2rem 1.5rem; padding: 1.5rem 2rem; background: #1c617f; border-radius: 16px 16px 0 0; }
.auth-card .brand-logo { height: 40px; border-radius: 0; }
.auth-card .brand-label { color: #cfe8f2; border: 0; padding: 0; margin: 0; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; }
@media (max-width: 600px) {
  .brand-logo { height: 26px; }
  .auth-card .brand { margin: -1.5rem -1.5rem 1.25rem; padding: 1.25rem 1.5rem; }
}

/* ── admin tabs + products ── */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.tab {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer;
  padding: .6rem 1rem; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.products .order-col { width: 1%; }
.order-btns { display: flex; flex-direction: column; gap: 2px; }
.order-btns .btn { padding: 0 .4rem; line-height: 1.2; font-size: .75rem; }
.pill.shown { background: #e3f6ee; color: var(--ok); }
.pill.hidden-p { background: #eef0f3; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; color: var(--ink-2); overflow-wrap: anywhere; }
#product-dialog { width: min(480px, calc(100vw - 2rem)); }
#product-dialog .dialog-head { margin-bottom: 1rem; }
@media (max-width: 760px) {
  .order-btns { flex-direction: row; }
}
