/* QHive License Console -- 简约大气.
   One accent colour, generous whitespace, borders instead of shadows, tables
   as the primary layout. Light and dark are both first-class. */

:root {
  color-scheme: light;

  --bg:            #fbfbfc;
  --surface:       #ffffff;
  --surface-sunk:  #f5f6f8;
  --border:        #e4e6ea;
  --border-strong: #d2d6dc;

  --text:          #16181d;
  --text-muted:    #5f6671;
  --text-faint:    #8b929d;

  --accent:        #3b5bdb;
  --accent-hover:  #324bb8;
  --accent-soft:   #eef1fd;
  --accent-text:   #ffffff;

  --ok:            #157f3d;
  --ok-soft:       #e7f6ec;
  --warn:          #8a5a00;
  --warn-soft:     #fdf3e0;
  --danger:        #b3261e;
  --danger-soft:   #fdecea;

  --chart-bar:  #3b5bdb;

  --radius:   10px;
  --radius-sm: 6px;
  --gap:      20px;
  --maxw:     1240px;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
          "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:            #0f1115;
    --surface:       #171a20;
    --surface-sunk:  #1d2128;
    --border:        #272c35;
    --border-strong: #353b47;
    --text:          #e8eaee;
    --text-muted:    #9aa2af;
    --text-faint:    #6e7683;
    --accent:        #7f9cf5;
    --accent-hover:  #93aaf7;
    --accent-soft:   #1c2235;
    --accent-text:   #0f1115;
    --ok:            #5fd38d;
    --ok-soft:       #14271c;
    --warn:          #e5b567;
    --warn-soft:     #2a2112;
    --danger:        #f58b84;
    --danger-soft:   #2d1613;
    --chart-bar:     #6a88ee;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:            #0f1115;
  --surface:       #171a20;
  --surface-sunk:  #1d2128;
  --border:        #272c35;
  --border-strong: #353b47;
  --text:          #e8eaee;
  --text-muted:    #9aa2af;
  --text-faint:    #6e7683;
  --accent:        #7f9cf5;
  --accent-hover:  #93aaf7;
  --accent-soft:   #1c2235;
  --accent-text:   #0f1115;
  --ok:            #5fd38d;
  --ok-soft:       #14271c;
  --warn:          #e5b567;
  --warn-soft:     #2a2112;
  --danger:        #f58b84;
  --danger-soft:   #2d1613;
  --chart-bar:     #6a88ee;
}

* { box-sizing: border-box; }
/* Any class that sets `display` (.row is flex) beats the UA's [hidden] rule,
   which is how the custom-days input showed while a preset was selected. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* --- app frame ------------------------------------------------------------ */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px; height: 56px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 600; font-size: 15px; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); align-self: center; }
.brand .sub { color: var(--text-faint); font-weight: 400; font-size: 12px; }

.nav { display: flex; gap: 2px; margin-left: 8px; }
.nav a {
  padding: 6px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-sunk); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--text-muted); font-size: 13px; }

main { max-width: var(--maxw); margin: 0 auto; padding: 28px 24px 72px; }
.page-head {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 22px;
}
.page-head .spacer { flex: 1; }
.page-head .crumb { color: var(--text-faint); font-size: 13px; }

/* --- primitives ----------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card + .card { margin-top: var(--gap); }
.card > header {
  display: flex; align-items: center; gap: 10px;
  margin: -4px 0 16px;
}
.card > header .spacer { flex: 1; }
.card-note { color: var(--text-muted); font-size: 13px; margin: -8px 0 16px; }

.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* 8 tiles. auto-fit would fit 7 across a wide screen and orphan the 8th on a
   row of its own, so pin an explicit column count per breakpoint instead. */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px)  { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1180px) { .stats { grid-template-columns: repeat(9, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat .label { color: var(--text-muted); font-size: 12px; letter-spacing: .02em; }
.stat .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px;
               font-variant-numeric: tabular-nums; }
.stat.accent .value { color: var(--accent); }
.stat.warn   .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  padding: 7px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { background: var(--surface-sunk); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
button.danger:hover { background: var(--danger-soft); }
button.sm { padding: 4px 9px; font-size: 12.5px; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
button.link:hover { background: none; text-decoration: underline; }

/* Preset chips (有效期档位). Radio inputs underneath, so keyboard and forms
   behave natively; the label is what gets styled. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label {
  margin: 0; cursor: pointer; user-select: none;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-strong); color: var(--text-muted); background: var(--surface);
}
.chips label:hover { color: var(--text); }
.chips input:checked + label { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chips input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips input:disabled + label { opacity: .45; cursor: not-allowed; }
.preview {
  margin-top: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--surface-sunk); font-size: 13px; color: var(--text-muted);
}
.preview strong { color: var(--text); font-variant-numeric: tabular-nums; }

label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; }
input, select, textarea {
  font: inherit; width: 100%;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent);
}
.field { margin-bottom: 14px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.hint { color: var(--text-faint); font-size: 12px; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .03em;
  color: var(--text-faint);
  padding: 0 12px 9px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-sunk); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; margin: 0 -20px -20px; padding: 0 20px; }
/* Without a min-width the table obeys width:100% and squeezes columns to
   nothing on a phone (a license id wrapping onto three lines) instead of
   letting the wrapper scroll. Below the breakpoint, make it overflow on
   purpose so horizontal scrolling does its job. */
@media (max-width: 860px) { .table-wrap table { min-width: 760px; } }
td .mono, td.mono, td a.mono { white-space: nowrap; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-sunk); color: var(--text-muted);
}
.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.accent { background: var(--accent-soft); color: var(--accent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 9px 20px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.empty { padding: 36px 20px; text-align: center; color: var(--text-faint); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }

/* --- login ---------------------------------------------------------------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; }
.login .brand { justify-content: center; margin-bottom: 6px; font-size: 18px; }
.login .tagline { text-align: center; color: var(--text-faint); margin-bottom: 26px; font-size: 13px; }

/* --- toast & modal -------------------------------------------------------- */

#toasts {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: calc(100% - 32px); max-width: 520px;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13px;
  animation: rise .18s ease-out;
  max-width: 100%;
}
.toast.err { background: var(--danger); color: #fff; }
.toast.ok  { background: var(--ok); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 12, 16, .5); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; padding: 22px;
}
.modal h2 { margin-bottom: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

/* Activation codes are shown exactly once, so the block has to look like
   something you must copy right now. */
.codes {
  background: var(--surface-sunk); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); padding: 14px; margin: 12px 0;
  font-family: var(--mono); font-size: 13px; line-height: 2;
  user-select: all; word-break: break-all;
}
.callout {
  border-left: 3px solid var(--warn); background: var(--warn-soft); color: var(--warn);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px;
}

@media (max-width: 720px) {
  .topbar { gap: 10px; padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .brand .sub { display: none; }
  .nav { order: 3; width: 100%; overflow-x: auto; padding-bottom: 8px; }
  main { padding: 20px 16px 56px; }
  .table-wrap { margin: 0 -20px; }
}

/* --- product polish ------------------------------------------------------ */

.page-head .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.cell-main { font-weight: 500; }
.cell-sub { color: var(--text-faint); font-size: 12px; margin-top: 1px; }
.cell-sub.mono { font-size: 11.5px; }

/* Single-series horizontal bars (region / version distribution).
   <=24px thick, 4px rounded data end, square at the baseline, 2px gap between
   bars; values in text ink, never in the bar colour. */
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar-row {
  display: grid; grid-template-columns: minmax(84px, 9em) 1fr 3.5em; align-items: center;
  gap: 12px; padding: 5px 4px; border-radius: var(--radius-sm); position: relative;
}
.bar-row:hover { background: var(--surface-sunk); }
.bar-row .bar-label { color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { height: 14px; }
.bar-row .bar-fill {
  height: 14px; min-width: 2px; background: var(--chart-bar);
  border-radius: 0 4px 4px 0;
}
.bar-row .bar-value { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.bar-row .bar-tip {
  display: none; position: absolute; right: 8px; top: -30px; z-index: 5; white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 12px; padding: 3px 8px; border-radius: 6px;
}
.bar-row:hover .bar-tip, .bar-row:focus-within .bar-tip { display: block; }

/* Device detail */
.detail-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-section { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.detail-section h3 { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 10px; }
.detail-section .kv { grid-template-columns: 6.5em 1fr; gap: 7px 14px; font-size: 13px; }
.meter { height: 6px; background: var(--surface-sunk); border-radius: 3px; margin-top: 4px; }
.meter > span { display: block; height: 6px; border-radius: 3px; background: var(--chart-bar); }

.device-link { white-space: nowrap; color: var(--text); text-decoration: none; border-bottom: 1px dashed var(--border-strong); cursor: pointer; }
.device-link:hover { color: var(--accent); border-bottom-color: var(--accent); text-decoration: none; }
.clip { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .sm { white-space: nowrap; }
.nowrap-cell .cell-main, .nowrap-cell .cell-sub { white-space: nowrap; }
td .cell-sub.clip-os { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- accounts ----------------------------------------------------------- */
.role-options { display: grid; gap: 8px; }
.role-option {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.role-option:hover { border-color: var(--border-strong); }
.role-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-option input { margin-top: 3px; width: auto; flex: none; }
.role-option > span { display: grid; gap: 2px; }
.role-option .muted { font-size: 12.5px; }
tr.muted-row td { opacity: .6; }

.account-menu { position: relative; }
.account-menu > button { display: flex; align-items: center; gap: 8px; }
.account-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 168px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12); padding: 6px; display: grid;
}
.account-menu .menu[hidden] { display: none; }
.account-menu .menu .menu-head { padding: 6px 10px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.account-menu .menu button { border: 0; background: none; text-align: left; padding: 8px 10px; }
.account-menu .menu button:hover { background: var(--surface-sunk); }
.readonly-note { margin-bottom: 16px; }
