/* T2Logic client panel
 * Colours are tokens: light values in :root, dark values in the two blocks below
 * ([data-theme=dark] = chosen by the user, media query = "same as system"). */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(31, 95, 191, .07), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(126, 87, 194, .06), transparent 60%),
             linear-gradient(170deg, #f7f8fb 0%, #eef1f6 55%, #f2f0f6 100%);
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --ink: #1d2330;
  --ink-2: #3c4455;
  --muted: #687083;
  --line: #e2e5eb;
  --field-line: #cdd2db;
  --field-bg: #ffffff;
  --field-disabled: #f1f3f6;
  --hover: #f3f5f8;
  --placeholder-bg: #e9ecf1;
  --placeholder-ink: #a3abbc;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --danger: #b4232f;
  --danger-bg: #fdf1f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);

  --topbar: linear-gradient(100deg, #161b26 0%, #1d2433 60%, #232a3c 100%);
  --topbar-ink: #d4d9e3;
  --topbar-muted: #aab2c3;

  --st-open: #1f5fbf;       --st-open-bg: #eef4fc;
  --st-processing: #b26b00; --st-processing-bg: #fff6e6;
  --st-resolved: #1d7f45;   --st-resolved-bg: #edf8f1;
  --st-cancelled: #6b7280;  --st-cancelled-bg: #f2f3f5;
  --waiting: #8a5a00; --waiting-bg: #fff3d6; --waiting-line: #f0d590;

  --ok-bg: #eef8f1;   --ok-line: #bfe3cb;   --ok-ink: #145c32;
  --err-bg: #fdf1f2;  --err-line: #f2c4c8;  --err-ink: #8e1b25;
  --info-bg: #eef4fc; --info-line: #c6d9f3; --info-ink: #1b4a8f;
  --note-bg: #fff8e8; --note-line: #f0dca8; --note-ink: #7a5400;
  --chip-bg: #e8eefa;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11151d;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(80, 140, 255, .10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(150, 110, 230, .08), transparent 60%),
             linear-gradient(170deg, #12161e 0%, #151a24 55%, #181624 100%);
  --surface: #1a202b;
  --surface-2: #1f2632;
  --ink: #e6e9ef;
  --ink-2: #c3c9d5;
  --muted: #959db0;
  --line: #2b3342;
  --field-line: #3a4354;
  --field-bg: #141922;
  --field-disabled: #1c222c;
  --hover: #232b38;
  --placeholder-bg: #232a36;
  --placeholder-ink: #5b6477;
  --accent: #5b9bff;
  --accent-ink: #0b1220;
  --danger: #ff7a84;
  --danger-bg: #3a1d22;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 10px rgba(0, 0, 0, .25);

  --topbar: linear-gradient(100deg, #0b0e14 0%, #10141c 60%, #151a25 100%);

  --st-open: #7fb0ff;       --st-open-bg: #172338;
  --st-processing: #f0b45a; --st-processing-bg: #2e2312;
  --st-resolved: #5fd08e;   --st-resolved-bg: #132a1e;
  --st-cancelled: #a1a8b5;  --st-cancelled-bg: #232832;
  --waiting: #f2c46b; --waiting-bg: #2e2513; --waiting-line: #5a4721;

  --ok-bg: #132a1e;   --ok-line: #24533a;   --ok-ink: #8fe0b0;
  --err-bg: #34191d;  --err-line: #5d2a31;  --err-ink: #ffa8af;
  --info-bg: #15233a; --info-line: #27406a; --info-ink: #a9c8ff;
  --note-bg: #2e2513; --note-line: #5a4721; --note-ink: #f2cf86;
  --chip-bg: #22304a;
}

/* "Same as system": dark tokens when the OS is dark and the user hasn't picked light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11151d;
    --bg-grad: radial-gradient(1200px 600px at 100% -10%, rgba(80, 140, 255, .10), transparent 60%),
               radial-gradient(900px 500px at -10% 110%, rgba(150, 110, 230, .08), transparent 60%),
               linear-gradient(170deg, #12161e 0%, #151a24 55%, #181624 100%);
    --surface: #1a202b;
    --surface-2: #1f2632;
    --ink: #e6e9ef;
    --ink-2: #c3c9d5;
    --muted: #959db0;
    --line: #2b3342;
    --field-line: #3a4354;
    --field-bg: #141922;
    --field-disabled: #1c222c;
    --hover: #232b38;
    --placeholder-bg: #232a36;
    --placeholder-ink: #5b6477;
    --accent: #5b9bff;
    --accent-ink: #0b1220;
    --danger: #ff7a84;
    --danger-bg: #3a1d22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 10px rgba(0, 0, 0, .25);
    --topbar: linear-gradient(100deg, #0b0e14 0%, #10141c 60%, #151a25 100%);
    --st-open: #7fb0ff;       --st-open-bg: #172338;
    --st-processing: #f0b45a; --st-processing-bg: #2e2312;
    --st-resolved: #5fd08e;   --st-resolved-bg: #132a1e;
    --st-cancelled: #a1a8b5;  --st-cancelled-bg: #232832;
    --waiting: #f2c46b; --waiting-bg: #2e2513; --waiting-line: #5a4721;
    --ok-bg: #132a1e;   --ok-line: #24533a;   --ok-ink: #8fe0b0;
    --err-bg: #34191d;  --err-line: #5d2a31;  --err-ink: #ffa8af;
    --info-bg: #15233a; --info-line: #27406a; --info-ink: #a9c8ff;
    --note-bg: #2e2513; --note-line: #5a4721; --note-ink: #f2cf86;
    --chip-bg: #22304a;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  min-height: 100%;
  background-color: var(--bg);
  background-image: var(--bg-grad);
  background-repeat: no-repeat;
}
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px; }
.main { padding-top: 28px; padding-bottom: 40px; min-height: 70vh; }
.footer { color: var(--muted); font-size: .85rem; padding-bottom: 24px; }

/* Top bar */
.topbar { background: var(--topbar); color: #fff; box-shadow: 0 1px 0 rgba(255, 255, 255, .04), 0 4px 18px rgba(10, 15, 25, .18); }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { color: #fff; display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-sub { color: var(--topbar-muted); font-size: .9rem; padding-left: 10px; border-left: 1px solid rgba(255, 255, 255, .18); }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { color: var(--topbar-ink); padding: 8px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav a.is-active { color: #fff; background: rgba(255, 255, 255, .14); }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-tools form { margin: 0; }
.langs { display: flex; gap: 4px; }
.flag { border: 0; padding: 3px; background: transparent; border-radius: 5px; cursor: pointer; line-height: 0; opacity: .55; transition: opacity .15s, background .15s; }
.flag img { width: 24px; height: 16px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .25); }
.flag:hover, .flag:focus-visible { opacity: 1; background: rgba(255, 255, 255, .1); }
.flag.is-current { opacity: 1; background: rgba(255, 255, 255, .14); }
.icon-btn { border: 1px solid rgba(255, 255, 255, .25); background: transparent; color: #fff; width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .i-moon { fill: currentColor; stroke: none; }
/* Show the moon in light mode (click = go dark), the sun in dark mode. */
.icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: block; }
:root[data-theme="dark"] .icon-btn .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .i-sun { display: block; }
  :root:not([data-theme="light"]) .icon-btn .i-moon { display: none; }
}
.logout { display: flex; align-items: center; gap: 10px; }
.who { color: var(--topbar-muted); font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.who:hover { color: #fff; text-decoration: none; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .3); background: transparent; }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .1); }

/* Layout helpers */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
/* Login page: box centred in the space between the top bar and the footer. */
.auth-center { min-height: calc(100vh - 200px); display: flex; align-items: center; justify-content: center; }
.auth-center .card.narrow { width: 100%; margin: 20px 0; }
.auth-center .form > .btn { justify-self: center; }
.center { text-align: center; }
.section-gap { margin-top: 28px; }
.narrow-left { max-width: 560px; }
.empty { color: var(--muted); text-align: center; padding: 32px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.stack > .card + .card, .stack > .card + section { margin-top: 20px; }
.stack > .card { margin-bottom: 0; }
.stack-sm { display: grid; gap: 8px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.page-head h1, .page-head h2 { margin: 0; }
.crumbs { margin-bottom: 6px; font-size: .9rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.push-right { margin-left: auto; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.nowrap { white-space: nowrap; }

/* Forms */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 5px; font-weight: 500; font-size: .92rem; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.choices { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.choices legend { font-weight: 500; font-size: .92rem; padding: 0; margin-bottom: 4px; }
.choices label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input, textarea, select {
  font: inherit; color: inherit;
  border: 1px solid var(--field-line); border-radius: 7px; padding: 9px 11px; background: var(--field-bg); width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 7px; }
.row input[type=file] { flex: 1; min-width: 0; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
input:disabled { background: var(--field-disabled); color: var(--muted); }
textarea { resize: vertical; min-height: 90px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font: inherit; font-weight: 500; cursor: pointer;
  padding: 9px 16px; border-radius: 7px; border: 1px solid var(--field-line); background: var(--surface); color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 11px; font-size: .88rem; }
.form > .btn { justify-self: start; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash-success { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); }
.flash-info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-ink); }
.notice { background: var(--note-bg); border: 1px solid var(--note-line); color: var(--note-ink); padding: 12px 14px; border-radius: 8px; margin: 0; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.tile-photo { aspect-ratio: 4 / 3; background: var(--placeholder-bg); }
.tile-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-nophoto { width: 100%; height: 100%; display: grid; place-items: center; font-size: 3rem; font-weight: 700; color: var(--placeholder-ink); }
.tile-body { padding: 16px 16px 8px; flex: 1; }
.tile-body h2 { margin-bottom: 6px; }
.tile-body p { color: var(--ink-2); font-size: .93rem; }
.tile-foot { padding: 0 16px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* Entries */
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.entry-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.entry-date { font-weight: 600; margin-right: 4px; }
.entry-text { white-space: normal; overflow-wrap: anywhere; }
.entry .form { margin-top: 4px; }
.entry-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.entry-actions form { margin: 0; }
.entry-actions .inline { display: flex; gap: 6px; }
.entry-actions select { width: auto; padding: 5px 8px; font-size: .88rem; }
.history summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
.history ul { margin: 8px 0 0; padding-left: 18px; font-size: .85rem; }

/* Badges */
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid currentColor; line-height: 1.6; }
a.badge:hover { text-decoration: none; }
.badge-open { color: var(--st-open); background: var(--st-open-bg); }
.badge-processing { color: var(--st-processing); background: var(--st-processing-bg); }
.badge-resolved { color: var(--st-resolved); background: var(--st-resolved-bg); }
.badge-cancelled { color: var(--st-cancelled); background: var(--st-cancelled-bg); }
.badge-received { color: var(--st-resolved); background: transparent; border-color: transparent; padding-left: 0; }
.badge-waiting { color: var(--waiting); background: var(--waiting-bg); border-color: var(--waiting-line); }

/* Filters & tables */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters input, .filters select { width: auto; min-width: 180px; }
.chip { background: var(--chip-bg); border-radius: 999px; padding: 4px 10px; font-size: .88rem; }
.chip a { margin-left: 4px; font-weight: 700; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.table tr.is-inactive td { color: var(--muted); }
.table .sort { color: inherit; display: inline-flex; align-items: center; gap: 5px; }
.table .sort:hover { color: var(--ink); text-decoration: none; }
.table .sort.is-sorted { color: var(--ink); }
.sort-arrow { font-size: .7rem; opacity: .45; }
.sort.is-sorted .sort-arrow { opacity: 1; color: var(--accent); }
.cell-user { white-space: nowrap; }
.cell-user > .avatar { margin-right: 8px; }
.cell-user > .badge, .cell-user > .muted { margin-left: 6px; }

.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.device-list li:last-child { border-bottom: 0; }
.device-list img, .thumb-empty { width: 48px; height: 36px; object-fit: cover; border-radius: 5px; background: var(--placeholder-bg); display: grid; place-items: center; color: var(--placeholder-ink); font-weight: 700; flex: none; }

/* Avatars */
.avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; object-fit: cover; font-weight: 600; color: #fff; letter-spacing: .02em; user-select: none; vertical-align: middle; }
.avatar-sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar-md { width: 44px; height: 44px; font-size: 1rem; }
.avatar-lg { width: 96px; height: 96px; font-size: 2rem; }
img.avatar { background: var(--placeholder-bg); }
.avatar-c0 { background: linear-gradient(135deg, #4f7bd9, #2e57b0); }
.avatar-c1 { background: linear-gradient(135deg, #2fa56f, #1b7a50); }
.avatar-c2 { background: linear-gradient(135deg, #d98a3a, #b5651d); }
.avatar-c3 { background: linear-gradient(135deg, #9b6bd6, #7445b5); }
.avatar-c4 { background: linear-gradient(135deg, #d6577a, #b03558); }
.avatar-c5 { background: linear-gradient(135deg, #2aa3b8, #1a7d90); }
.avatar-c6 { background: linear-gradient(135deg, #7d8798, #59627a); }
.avatar-c7 { background: linear-gradient(135deg, #c4a52b, #9c8113); }
.topbar .avatar { box-shadow: 0 0 0 2px rgba(255, 255, 255, .25); }
.avatar-edit { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.avatar-edit .stack-sm { flex: 1; min-width: 200px; }
.title-avatar { display: flex; align-items: center; gap: 12px; }

/* Narrower screens: the subtitle and user's name go first, then tools take their own row. */
@media (max-width: 1240px) {
  .topbar.has-nav .brand-sub, .topbar.has-nav .who-name { display: none; }
}
@media (max-width: 760px) {
  .topbar-tools { margin-left: 0; width: 100%; justify-content: space-between; padding-bottom: 10px; }
  .who-name { display: none; }
  .brand-sub { display: none; }
  .filters input, .filters select { min-width: 0; flex: 1; }
}
