:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c232d;
  --border: #2b3340;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --ok: #2ea043;
  --warn: #d29922;
  --err: #f85149;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.card h1 { margin: 0 0 4px; font-size: 20px; }
.card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
button.primary {
  width: 100%;
  padding: 11px;
  background: var(--accent-2);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover { background: var(--accent); }
button.primary:disabled { opacity: 0.6; cursor: default; }
.error { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---------- viewer ---------- */
.viewer-body { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  flex-wrap: wrap;
}
.toolbar .brand { font-weight: 700; letter-spacing: 0.3px; }
.toolbar select, .toolbar button {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent); }
.toolbar .spacer { flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.status-txt { color: var(--muted); font-size: 12px; }

.stage {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}
#screen {
  max-width: 100%;
  max-height: 100%;
  image-rendering: auto;
  cursor: crosshair;
  background: #000;
  display: block;
}
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
  pointer-events: none;
  padding: 24px;
}
.overlay.hidden { display: none; }

/* ---------- app shell (dashboard / admin) ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.tb-left { display: flex; align-items: center; gap: 12px; }
.tb-title { color: var(--muted); font-size: 14px; }
.tb-right { display: flex; align-items: center; gap: 10px; }
.tb-user { color: var(--muted); font-size: 13px; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 20px 60px; }
.page-sub { color: var(--muted); margin: -4px 0 22px; }

h2.section { font-size: 15px; margin: 28px 0 12px; color: var(--fg); }
h2.section:first-of-type { margin-top: 8px; }

.btn {
  background: var(--panel-2); color: var(--fg); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 12px; font-size: 13px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #5b2526; color: #ff9a92; }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.tile h3 { margin: 0; font-size: 15px; }
.tile .meta { color: var(--muted); font-size: 12px; }
.tile .actions { display: flex; gap: 8px; margin-top: auto; flex-wrap: wrap; }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr:hover td { background: rgba(255,255,255,.02); }
td .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: rgba(46,160,67,.15); color: #6edb8f; border-color: #214d2c; }
.badge.warn { background: rgba(210,153,34,.15); color: #e5bb5a; border-color: #5a4a1e; }
.badge.err { background: rgba(248,81,73,.15); color: #ff9a92; border-color: #5b2526; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-size: 13px; }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }
.tabpane { display: none; } .tabpane.active { display: block; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 20px; }
.inline-form input, .inline-form select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--fg); padding: 7px 10px; font-size: 13px;
}
.inline-form input:focus, .inline-form select:focus { outline: none; border-color: var(--accent); }
.card .field input[type=date] { color-scheme: dark; }
.auth-links { margin-top: 14px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-links a { color: var(--accent); text-decoration: none; }

.banner { padding: 12px 14px; border-radius: 9px; margin-bottom: 18px; font-size: 13px; }
.banner.ok { background: rgba(46,160,67,.12); border: 1px solid #214d2c; color: #8fe0a6; }
.banner.warn { background: rgba(210,153,34,.12); border: 1px solid #5a4a1e; color: #e5bb5a; }

.price { font-weight: 700; color: var(--fg); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--fg);
  padding: 11px 16px; border-radius: 9px; font-size: 13px; opacity: 0;
  transition: all .25s; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { border-color: #214d2c; } .toast.err { border-color: #5b2526; }

/* ---------- viewer file drawer ---------- */
.filedrawer {
  position: absolute; top: 0; right: 0; height: 100%; width: 340px; max-width: 90vw;
  background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 20; box-shadow: -8px 0 24px rgba(0,0,0,.4);
}
.filedrawer[hidden] { display: none; }
.fd-head { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.fd-body { padding: 14px; overflow-y: auto; }
.fd-hint { color: var(--muted); font-size: 12px; margin: 0 0 14px; line-height: 1.5; }
.fd-hint code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.fd-upload { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.fd-upload select, .fd-upload input[type=file] {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--fg); padding: 7px 9px; font-size: 13px; width: 100%;
}
.fd-status { font-size: 12px; color: var(--muted); min-height: 16px; margin-bottom: 10px; }
.fd-group-title { color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; margin: 14px 0 6px; }
.fd-file { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 7px; margin-bottom: 6px; font-size: 12px; }
.fd-file .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fd-file .fsz { color: var(--muted); font-size: 11px; margin-left: 8px; white-space: nowrap; }
.fd-file button { background: none; border: 0; color: var(--err); cursor: pointer; font-size: 14px; }

/* ---------- admin control panel ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; border-bottom: 1px solid var(--border); }
.side-brand .logo { background: var(--accent-2); color: #fff; border-radius: 7px; padding: 4px 8px; font-size: 13px; font-weight: 800; letter-spacing: .5px; }
.side-brand .pname { font-size: 14px; font-weight: 600; }
.side-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.side-link { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 13.5px; border: 1px solid transparent; }
.side-link:hover { background: var(--panel-2); color: var(--fg); }
.side-link.active { background: rgba(47,129,247,.12); color: #cfe0ff; border-color: rgba(47,129,247,.25); }
.side-link svg { width: 18px; height: 18px; flex: 0 0 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.side-link .count { margin-left: auto; background: var(--accent-2); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; min-width: 20px; text-align: center; }
.side-foot { border-top: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 9px; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: 0 0 34px; }
.who-name { font-size: 13px; } .who-role { font-size: 11px; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 28px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(8px); z-index: 5; }
.main-head h1 { font-size: 19px; margin: 0; }
.main-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.content { padding: 24px 28px 64px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.stat .k svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; opacity: .8; }
.stat .v { font-size: 27px; font-weight: 750; margin-top: 10px; letter-spacing: -.5px; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 3px; }
.stat.accent .v { color: #7cb0ff; } .stat.ok .v { color: #6edb8f; } .stat.warn .v { color: #e5bb5a; } .stat.money .v { color: #67d9c0; }

.panel-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-bottom: 20px; }
.panel-card .ph { padding: 13px 18px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13.5px; display: flex; justify-content: space-between; align-items: center; }
.panel-card .ph .hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.panel-card .pb { padding: 6px 4px; }
.panel-card .pb.pad { padding: 16px 18px; }
.panel-card table td:first-child, .panel-card table th:first-child { padding-left: 16px; }
.panel-card table td:last-child, .panel-card table th:last-child { padding-right: 16px; }
.panel-card table tr:last-child td { border-bottom: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.toolbar-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; }
.toolbar-card .tc-title { font-size: 11px; color: var(--muted); margin-bottom: 11px; text-transform: uppercase; letter-spacing: .6px; }

.user-cell { display: flex; align-items: center; gap: 9px; }
.user-cell .avatar { width: 28px; height: 28px; font-size: 11px; flex: 0 0 28px; }
.meter { height: 6px; border-radius: 4px; background: var(--panel-2); overflow: hidden; width: 120px; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; color: var(--muted); }

@media (max-width: 820px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; overflow-x: auto; }
  .side-brand { border-bottom: 0; border-right: 1px solid var(--border); white-space: nowrap; }
  .side-nav { flex-direction: row; }
  .side-foot { display: none; }
  .two-col { grid-template-columns: 1fr; }
  .content, .main-head { padding-left: 16px; padding-right: 16px; }
}

/* ---------- client dashboard ---------- */
.dash-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.dash-top .brand-wrap { display: flex; align-items: center; gap: 10px; }
.dash-top .logo { background: var(--accent-2); color: #fff; border-radius: 7px; padding: 4px 8px; font-size: 13px; font-weight: 800; letter-spacing: .5px; }
.dash-top .pname { font-weight: 600; font-size: 14px; }
.dash-top .right { display: flex; align-items: center; gap: 10px; }
.hero { margin: 26px 0 20px; }
.hero h1 { font-size: 25px; margin: 0; letter-spacing: -.3px; }
.hero p { color: var(--muted); margin: 7px 0 0; font-size: 14px; }

.term-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.term-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 12px; transition: border-color .15s, transform .15s, box-shadow .15s;
}
.term-card:hover { border-color: rgba(47,129,247,.45); transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.term-thumb {
  height: 128px; border-radius: 10px; position: relative; overflow: hidden;
  background: radial-gradient(130% 130% at 15% 0%, #16263f 0%, #0b111c 60%);
  border: 1px solid var(--border); display: flex; align-items: flex-end;
}
.term-thumb svg { width: 100%; height: 72%; display: block; }
.term-thumb .tbadge { position: absolute; top: 10px; left: 10px; }
.term-thumb .tmon { position: absolute; top: 10px; right: 12px; color: var(--muted); font-size: 11px; }
.term-card .t-title { font-weight: 650; font-size: 15.5px; }
.term-card .t-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.term-card .t-actions { display: flex; gap: 8px; margin-top: auto; }
.term-card .t-actions .btn { flex: 1; justify-content: center; }

.offer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.offer-card { background: var(--panel); border: 1px solid var(--border); border-radius: 13px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.offer-card h3 { margin: 0; font-size: 15px; }
.offer-card .price { font-size: 22px; font-weight: 750; }
.offer-card .price small { font-size: 12px; color: var(--muted); font-weight: 400; }
.offer-card .o-actions { display: flex; gap: 8px; margin-top: auto; }
.empty-card { border: 1px dashed var(--border); border-radius: 14px; padding: 30px; text-align: center; color: var(--muted); }
.empty-card .big { font-size: 15px; color: var(--fg); margin-bottom: 6px; }
.months-sel {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--fg); padding: 6px 8px; font-size: 13px;
}
.months-sel:focus { outline: none; border-color: var(--accent); }
.months-row { display: flex; align-items: center; gap: 8px; }
.months-row .price { font-size: 16px; margin-left: auto; }
.renew-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.renew-row .months-sel { padding: 4px 7px; font-size: 12px; }
