:root {
  --ink: #172033;
  --muted: #70798e;
  --line: #e5e8ef;
  --surface: #ffffff;
  --canvas: #f3f5f9;
  --nav: #10182b;
  --primary: #5a55e8;
  --primary-dark: #4641c9;
  --green: #1aa56f;
  --amber: #d68a1f;
  --red: #cf4e5b;
  --blue: #3887d6;
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: #7e87a0; font-size: 11px; font-weight: 800; letter-spacing: .16em; }

.toast { position: fixed; z-index: 100; top: 24px; left: 50%; transform: translate(-50%, -20px); min-width: 280px; max-width: min(560px, calc(100vw - 32px)); padding: 13px 18px; border-radius: 12px; color: white; background: #1e293b; box-shadow: 0 18px 45px #0f172a35; opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b43e4a; }
.toast.success { background: #137e57; }

.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(460px, 1.15fr) minmax(420px, .85fr); }
.auth-brand { position: relative; overflow: hidden; padding: clamp(54px, 8vw, 110px); color: white; background: radial-gradient(circle at 75% 20%, #655fe8 0, transparent 33%), linear-gradient(145deg, #121a31, #20265c 72%, #34308d); }
.auth-brand::after { content: ""; position: absolute; width: 420px; height: 420px; right: -160px; bottom: -190px; border: 1px solid #ffffff28; border-radius: 50%; box-shadow: 0 0 0 58px #ffffff08, 0 0 0 118px #ffffff08; }
.brand-mark { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 70px; border-radius: 15px; font-weight: 900; font-size: 24px; color: #fff; background: linear-gradient(135deg, #8a82ff, #5b55e8); box-shadow: 0 12px 30px #0004; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 11px; font-size: 18px; }
.auth-brand .eyebrow { color: #aca8ff; }
.auth-brand h1 { max-width: 720px; margin: 0; font-size: clamp(42px, 5vw, 72px); line-height: 1.08; letter-spacing: -.045em; }
.auth-lead { max-width: 620px; margin: 28px 0 54px; color: #d5d8ef; font-size: 17px; line-height: 1.8; }
.promise-list { display: grid; gap: 20px; max-width: 590px; }
.promise-list > div { display: grid; grid-template-columns: 44px 1fr; gap: 14px; align-items: start; }
.promise-list > div > span { color: #9691ff; font-weight: 800; }
.promise-list p { margin: 0; color: #c6cae3; line-height: 1.55; }
.promise-list strong { display: block; margin-bottom: 3px; color: #fff; }
.auth-panel { display: grid; place-items: center; padding: 48px; background: #fafbfc; }
.auth-card { width: min(440px, 100%); }
.auth-card h2 { margin: 0 0 10px; font-size: 34px; letter-spacing: -.03em; }
.auth-card > .muted { margin: 0 0 32px; }
label { display: grid; gap: 8px; color: #3d4557; font-size: 13px; font-weight: 700; }
input, textarea, select { width: 100%; border: 1px solid #dce0e9; border-radius: 10px; padding: 12px 13px; color: var(--ink); background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: #817cef; box-shadow: 0 0 0 3px #5a55e815; }
textarea { resize: vertical; line-height: 1.55; }
label small, .form-help { color: #8a92a3; font-size: 12px; font-weight: 400; }
#auth-form { display: grid; gap: 18px; }
.form-help { margin-top: 18px; text-align: center; }
.notice { margin: 0 0 22px; padding: 13px 14px; border-radius: 10px; line-height: 1.5; }
.notice.warning { color: #7c5416; background: #fff3d9; border: 1px solid #f5dda9; }

.button { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 750; transition: .15s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button.primary { color: white; background: var(--primary); box-shadow: 0 7px 18px #5a55e82a; }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: #4b5568; background: #eef0f5; }
.button.dark { color: white; background: #171f33; }
.button.danger { color: #b33d4a; background: #fff0f1; }
.button.small { padding: 7px 10px; border-radius: 8px; font-size: 12px; }
.wide { width: 100%; }
.text-button, .icon-button { border: 0; color: #6863d8; background: transparent; font-weight: 700; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: #606a7e; font-size: 20px; }
.icon-button:hover { background: #eef0f5; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px 1fr; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; width: 230px; display: flex; flex-direction: column; padding: 24px 18px; color: #dce2f1; background: var(--nav); }
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 32px; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { color: #fff; }
.sidebar-brand span { margin-top: 2px; color: #78839d; font-size: 11px; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; color: #9ea8bd; background: transparent; text-align: left; font-weight: 700; }
.nav-item span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 7px; color: #aeb7c9; background: #ffffff0d; font-size: 11px; }
.nav-item:hover, .nav-item.active { color: #fff; background: #ffffff10; }
.nav-item.active span { color: #fff; background: var(--primary); }
.sidebar-foot { margin-top: auto; padding: 18px 10px 4px; border-top: 1px solid #ffffff12; }
.server-state { display: flex; gap: 9px; align-items: center; margin-bottom: 12px; color: #9ba6bc; font-size: 12px; }
.server-state i { width: 8px; height: 8px; border-radius: 50%; background: #31c987; box-shadow: 0 0 0 4px #31c98718; }
.sidebar-foot a { color: #737f99; font-size: 12px; text-decoration: none; }
.workspace { grid-column: 2; min-width: 0; padding: 0 36px 48px; }
.topbar { position: sticky; z-index: 8; top: 0; display: flex; justify-content: space-between; align-items: center; min-height: 102px; padding: 20px 0; background: #f3f5f9ed; backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 27px; letter-spacing: -.025em; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 9px; margin-left: 5px; padding-left: 16px; border-left: 1px solid var(--line); }
.user-chip > span { display: grid; place-items: center; width: 35px; height: 35px; border-radius: 10px; color: #4d49c9; background: #e6e5ff; font-weight: 800; }
.user-chip strong, .user-chip small { display: block; }
.user-chip strong { font-size: 13px; }
.user-chip small { color: #8a92a4; font-size: 10px; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: .5; transform: translateY(3px); } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-card { position: relative; overflow: hidden; min-height: 146px; padding: 23px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 5px 16px #18233b08; }
.stat-card::after { content: ""; position: absolute; top: 0; right: 0; width: 6px; height: 100%; background: currentColor; opacity: .65; }
.stat-card span, .stat-card small { display: block; color: #7b8498; }
.stat-card span { font-size: 13px; font-weight: 700; }
.stat-card strong { display: block; margin: 16px 0 5px; color: var(--ink); font-size: 30px; letter-spacing: -.035em; }
.stat-card small { font-size: 11px; }
.stat-card.indigo { color: #6b65eb; }.stat-card.green { color: var(--green); }.stat-card.amber { color: var(--amber); }.stat-card.blue { color: var(--blue); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 18px; margin-bottom: 18px; }
.panel { border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: 0 5px 18px #18233b08; }
.panel-heading { display: flex; justify-content: space-between; gap: 20px; align-items: start; padding: 22px 24px 16px; }
.panel-heading h2, .workflow-card h2 { margin: 0; font-size: 18px; }
.latest-list { min-height: 220px; padding: 0 24px 22px; }
.latest-item { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; gap: 13px; align-items: center; padding: 14px 0; border-top: 1px solid #edf0f5; }
.latest-item:first-child { border-top: 0; }
.app-symbol { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; color: #554fd0; background: #eeedff; font-weight: 850; }
.latest-item strong, .latest-item small { display: block; }
.latest-item small { overflow: hidden; margin-top: 3px; color: #8992a5; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.version-pill { padding: 6px 9px; border-radius: 999px; color: #197c59; background: #e8f7f1; font-size: 11px; font-weight: 800; }
.version-pill.empty { color: #8a6a34; background: #fff3dc; }
.workflow-card { padding: 25px; color: white; background: linear-gradient(155deg, #1d2740, #121a2e); }
.workflow-card .eyebrow { color: #8883ef; }
.workflow-list { display: grid; gap: 19px; margin: 25px 0; padding: 0; list-style: none; }
.workflow-list li { display: grid; grid-template-columns: 30px 1fr; gap: 12px; }
.workflow-list b { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 50%; color: #fff; background: #5b56df; font-size: 11px; }
.workflow-list strong, .workflow-list span { display: block; }
.workflow-list strong { font-size: 13px; }.workflow-list span { margin-top: 3px; color: #9ca6bc; font-size: 11px; line-height: 1.45; }
.recent-panel { min-height: 220px; }
.empty-state { display: grid; place-items: center; min-height: 170px; color: #939bab; font-size: 13px; }

.section-intro { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 7px 0 20px; }
.section-intro h2 { margin: 0 0 7px; font-size: 22px; }.section-intro p { margin: 0; color: var(--muted); font-size: 13px; }
.form-panel { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 5px 24px 24px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: end; gap: 10px; padding-top: 3px; }
.app-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.app-card { padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.app-card-head { display: flex; justify-content: space-between; align-items: start; }
.app-card h3 { margin: 16px 0 5px; font-size: 17px; }.app-card p { min-height: 40px; margin: 0 0 19px; color: #7f889b; font-size: 12px; line-height: 1.6; }
.app-card code { display: block; overflow: hidden; padding: 9px 10px; border-radius: 8px; color: #5b6478; background: #f4f5f8; font-size: 11px; text-overflow: ellipsis; }
.app-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; color: #8992a5; font-size: 11px; }
.file-drop { place-items: center; padding: 27px; border: 1px dashed #cbd0dc; border-radius: 13px; background: #fafbfe; text-align: center; cursor: pointer; }
.file-drop:hover { border-color: #8781ef; background: #f8f7ff; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop .file-icon { display: grid; place-items: center; width: 38px; height: 38px; margin-bottom: 7px; border-radius: 11px; color: #5b55dc; background: #e9e8ff; font-size: 21px; }
.file-drop strong { font-size: 13px; }.file-drop small { margin-top: 3px; }
.upload-progress > div { overflow: hidden; height: 7px; border-radius: 999px; background: #e8eaf0; }
.upload-progress > div span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #5a55e8, #8580f1); transition: width .2s; }
.upload-progress p { display: flex; justify-content: space-between; margin: 8px 0 0; font-size: 12px; }.upload-progress p small { color: #9098a9; }
.filter-row { display: flex; justify-content: space-between; align-items: center; padding: 19px 22px; border-bottom: 1px solid var(--line); }
.filter-row strong, .filter-row span { display: block; }.filter-row span { margin-top: 2px; color: #929aab; font-size: 11px; }
.filters { display: flex; gap: 8px; }.filters select { width: auto; min-width: 130px; padding: 8px 10px; font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 18px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: middle; font-size: 12px; }
th { color: #8c94a5; background: #fbfcfd; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td strong, td small { display: block; } td small { margin-top: 3px; color: #9098a9; }
.status { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.status.draft { color: #9a6414; background: #fff2d7; }.status.published { color: #137b55; background: #e4f7ef; }.status.withdrawn { color: #8b5260; background: #f6e9ed; }
.row-actions { display: flex; gap: 7px; justify-content: end; }
.sha { max-width: 150px; overflow: hidden; color: #737c8f; font-family: Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }
.audit-list { padding: 8px 23px; }
.audit-item { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 13px; align-items: center; padding: 16px 0; border-bottom: 1px solid #edf0f4; }
.audit-item:last-child { border-bottom: 0; }.audit-dot { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #5b56d4; background: #eeedff; font-size: 11px; font-weight: 800; }
.audit-item strong, .audit-item small { display: block; }.audit-item small { margin-top: 4px; color: #929aab; }.audit-item time { color: #929aab; font-size: 11px; }

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .app-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }.auth-brand { display: none; }
  .sidebar { position: static; width: auto; padding: 15px; }.app-shell { display: block; }.sidebar-brand { padding-bottom: 15px; }.sidebar nav { display: flex; overflow-x: auto; }.nav-item { width: auto; white-space: nowrap; }.sidebar-foot { display: none; }
  .workspace { padding: 0 18px 35px; }.topbar { min-height: 85px; }.user-chip { display: none; }
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .auth-panel { padding: 30px 22px; }.stat-grid, .app-grid, .form-grid { grid-template-columns: 1fr; }.form-grid .full { grid-column: auto; }
  .topbar-actions > .button { display: none; }.topbar h1 { font-size: 23px; }.workspace { padding-inline: 12px; }
  .stat-card { min-height: 125px; }.section-intro { align-items: center; }.filters { display: none; }
}
/* Device authorization uses the existing panel and form styles. */
#view-devices > .panel { padding: 24px; margin-bottom: 20px; }
#view-devices > .panel > h2 { margin: 0 0 18px; font-size: 20px; }
#device-code-form { display: grid; grid-template-columns: minmax(0, 1fr) 160px auto; gap: 16px; align-items: end; }
#device-new-code { overflow-wrap: anywhere; user-select: all; }
@media (max-width: 900px) { #device-code-form { grid-template-columns: 1fr; } }
