:root {
  color-scheme: light;
  font: 14px/1.45 system-ui, "Segoe UI", sans-serif;
  --bg: #f3f3f3;
  --surface: #fff;
  --text: #252526;
  --muted: #616161;
  --border: #cecece;
  --accent: #007acc;
  --danger: #b52020;
  --ok: #20753c;
  --chrome: #e8e8e8;
  --panel: #f3f3f3;
  --hover: #e4e6e9;
  --sidebar-width: 232px;
  --audit-sidebar-width: 320px;
  --title-height: 56px;
  --tab-height: 36px;
  --status-height: 28px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1e1e1e;
  --surface: #1e1e1e;
  --text: #d4d4d4;
  --muted: #aaa;
  --border: #454545;
  --danger: #f48771;
  --ok: #89d185;
  --chrome: #323233;
  --panel: #252526;
  --hover: #37373d;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { color: var(--text); background: var(--bg); }
button, input, select { min-height: 32px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 4px; color: var(--text); background: var(--surface); font: inherit; }
button { cursor: pointer; }
button:hover { background: var(--hover); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:disabled { cursor: wait; opacity: .6; }
label { display: grid; gap: 6px; color: var(--text); font-weight: 500; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgb(0 122 204 / 22%); }
#app[hidden], #login-panel[hidden], .workspace-screen[hidden], #workspace-empty[hidden], #issued-key[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); padding: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); box-shadow: 0 8px 32px rgb(0 0 0 / 10%); }
.login-brand { margin-bottom: 28px; text-align: center; }
.login-logo { width: 56px; height: 56px; margin: 0 auto 10px; display: grid; place-items: center; border-radius: 8px; color: #fff; background: var(--accent); font-size: 30px; font-weight: 700; }
.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.login-brand h1 { margin: 4px 0 6px; font-size: 28px; letter-spacing: -.4px; }
.login-brand > p:last-child { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: 16px; }
.login-form input { min-height: 40px; }
.primary { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.primary:hover { color: #fff; background: #168ddd; }
.message { margin: 0; color: var(--ok); }
.message.error { color: var(--danger); }
.message:empty { display: none; }
#login-message { margin-top: 16px; }

.ide-titlebar { position: fixed; inset: 0 0 auto; z-index: 30; height: var(--title-height); display: flex; align-items: center; gap: 12px; padding: 0 12px; color: var(--text); background: var(--chrome); border-bottom: 1px solid var(--border); }
.ide-titlebar strong { font-size: 15px; }
.ide-titlebar > span { color: var(--muted); font-size: 13px; }
.global-search { position: relative; flex: 1; min-width: 140px; max-width: 560px; margin: 0 auto; }
.global-search input { width: 100%; min-height: 34px; padding: 5px 10px; }
.global-search-results { position: fixed; top: calc(var(--title-height) - 1px); left: clamp(12px, calc(var(--sidebar-width) + 12px), 34vw); z-index: 45; width: min(560px, calc(100vw - 24px)); max-height: 60vh; overflow: auto; padding: 5px; border: 1px solid var(--border); border-radius: 0 0 5px 5px; background: var(--panel); box-shadow: 0 8px 24px rgb(0 0 0 / 18%); }
.global-search-results[hidden] { display: none; }
.global-search-result { width: 100%; display: grid; gap: 2px; padding: 8px 10px; border: 0; border-radius: 3px; background: transparent; text-align: left; }
.global-search-result strong { font-weight: 600; }
.global-search-result span, .global-search-empty { color: var(--muted); font-size: 12px; }
.global-search-empty { padding: 12px; }
.icon-button { width: 36px; min-height: 34px; display: grid; place-items: center; padding: 4px; border: 0; background: transparent; }
.icon-button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.titlebar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.theme-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.theme-control select { min-width: 82px; height: 30px; min-height: 30px; }
.quiet { color: var(--text); background: var(--surface); }

.ide-sidebar { position: fixed; inset: var(--title-height) auto 0 0; z-index: 20; width: var(--sidebar-width); display: flex; flex-direction: column; padding: 14px 8px 10px; overflow: auto; background: var(--panel); border-right: 1px solid var(--border); transition: transform 160ms ease, visibility 160ms ease; }
.ide-sidebar-title { padding: 0 12px 14px; color: var(--muted); font-size: 12px; letter-spacing: .9px; }
.ide-sidebar nav { display: grid; gap: 2px; }
.nav-group-label { padding: 6px 8px 4px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .35px; }
.workspace-nav-button { width: 100%; min-height: 34px; display: flex; align-items: center; gap: 9px; padding: 5px 10px; border: 0; background: transparent; text-align: left; }
.workspace-nav-button:hover { background: var(--hover); }
.workspace-nav-button[aria-current="page"] { background: var(--hover); box-shadow: inset 2px 0 var(--accent); font-weight: 600; }
.nav-icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-footer { margin-top: 0; padding: 12px 8px 0; border-top: 1px solid var(--border); color: var(--muted); }
.sidebar-action { margin-top: auto; padding: 12px 8px; border-top: 1px solid var(--border); }
.sidebar-action .nav-group-label { padding-left: 4px; }
.sidebar-action button { width: 100%; min-height: 34px; text-align: center; }
.sidebar-user { display: flex; align-items: center; gap: 9px; }
.sidebar-user > span { font-size: 16px; }
.user-avatar { width: 32px; height: 32px; min-height: 32px; flex: none; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; color: #fff; background: var(--accent); font-size: 14px; font-weight: 600; }
.user-avatar:hover { color: #fff; background: #168ddd; }
.user-avatar:focus-visible { outline-offset: 2px; }

.ide-tabbar { position: fixed; top: var(--title-height); right: var(--audit-sidebar-width); left: var(--sidebar-width); z-index: 19; height: var(--tab-height); background: var(--panel); border-bottom: 1px solid var(--border); transition: left 160ms ease, right 160ms ease; }
.ide-tabs { height: 100%; display: flex; align-items: stretch; gap: 2px; overflow: auto; padding: 3px 6px 0; }
.ide-tab { display: flex; flex: none; align-items: center; min-height: 30px; border: 1px solid transparent; border-bottom: 0; border-radius: 4px 4px 0 0; background: var(--panel); }
.ide-tab.is-active { background: var(--surface); border-color: var(--border); box-shadow: inset 0 2px var(--accent); }
.ide-tab-open { min-height: 29px; padding: 0 10px; border: 0; background: transparent; color: var(--muted); }
.ide-tab-open[aria-current="page"] { color: var(--text); font-weight: 550; }
.ide-tab-close { width: 22px; min-height: 22px; margin: 0 4px 0 0; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; }
.ide-tab-close:hover { background: var(--hover); color: var(--text); }

.workspace-area { position: fixed; inset: calc(var(--title-height) + var(--tab-height)) var(--audit-sidebar-width) var(--status-height) var(--sidebar-width); min-width: 0; overflow: auto; background: var(--surface); transition: left 160ms ease, right 160ms ease; }
.workspace-card { min-height: 100%; background: var(--surface); }
.workspace-section { padding: 20px 24px; border-bottom: 1px solid var(--border); }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-header > button[hidden] { display: none; }
.section-header h2 { margin: 0; font-size: 18px; }
.section-header p { margin: 4px 0 0; color: var(--muted); }
.customer-actions { min-width: 170px; white-space: nowrap; }
.customer-actions button { margin: 0 4px 4px 0; }
.store-actions { min-width: 150px; white-space: nowrap; }
.store-actions button { margin: 0 4px 4px 0; }
#customers tr[tabindex="0"] { cursor: pointer; }
#customers tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.customer-name { font-weight: 600; }
tr.is-selected { background: var(--hover); box-shadow: inset 2px 0 var(--accent); }
#customer-history[hidden] { display: none !important; }
.search-result-highlight { animation: search-highlight 1.8s ease-out; }
@keyframes search-highlight { 0%, 55% { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); } 100% { background: transparent; } }
.customer-dialog-card { width: min(540px, 100%); }
.customer-dialog-form { display: grid; gap: 12px; }
.customer-dialog-form input { min-height: 36px; }
.subscription-dialog-card { width: min(500px, 100%); }
.subscription-dialog-form select { min-height: 36px; }
.subscription-dialog-customer { margin: 0; color: var(--muted); }
.issue-dialog-card { width: min(500px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; }
.issue-dialog-form input, .issue-dialog-form select { min-height: 36px; }
.store-dialog-card { width: min(760px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; }
.store-dialog-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.store-dialog-form input { min-height: 36px; }
.store-dialog-form > label:first-child, .store-dialog-form > label:nth-child(2),
.store-dialog-form > label:nth-child(3), .store-dialog-form > p,
.store-dialog-actions { grid-column: 1 / -1; }
.store-dialog-actions { margin-top: 0; }
.customer-delete-note { margin: 0; color: var(--danger); }
.customer-dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.customer-dialog-spacer { flex: 1; }
.danger-button { color: #fff; border-color: var(--danger); background: var(--danger); }
.danger-button:hover { color: #fff; filter: brightness(1.08); }
.danger-button:disabled { cursor: not-allowed; opacity: .5; }
.issued { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; margin-top: 16px; padding: 14px; border: 1px solid #b6d9bc; background: color-mix(in srgb, var(--ok) 8%, var(--surface)); overflow-wrap: anywhere; }
.issued strong { grid-column: 1 / -1; }
.issued code { font-size: 14px; }
.key-cell { min-width: 190px; }
.key-cell[hidden], .key-cell code[hidden], .key-cell button[hidden] { display: none; }
.key-cell code { display: block; max-width: 220px; margin: 5px 0; overflow-wrap: anywhere; font-size: 12px; }
.key-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.key-actions button { min-height: 28px; padding: 3px 7px; font-size: 12px; }
.table-wrap { width: 100%; overflow: auto; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; color: var(--text); background: var(--panel); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--hover); }
.subscription-customer-cell { min-width: 190px; }
.subscription-customer-cell strong, .subscription-store-name { display: block; }
.subscription-store-name { margin-top: 3px; color: var(--muted); font-size: 12px; }
.license-expiry-cell { min-width: 120px; white-space: nowrap; }
.device-uuid { max-width: 220px; overflow-wrap: anywhere; }
.device-uuid > span { font-family: ui-monospace, monospace; font-size: 12px; }
.reset-binding { display: block; min-height: 24px; margin-top: 6px; padding: 2px 0; border: 0; background: transparent; color: var(--danger); font: inherit; font-size: 11px; text-align: left; }
.workspace-empty { padding: 40px 24px; color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.ide-statusbar { position: fixed; inset: auto 0 0; left: var(--sidebar-width); z-index: 30; height: var(--status-height); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px; color: #fff; background: #007acc; font-size: 12px; transition: left 160ms ease; }
.statusbar-context { min-width: 0; display: flex; align-items: center; gap: 14px; }
#status-message { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status-message.error { color: #ffe2df; font-weight: 600; }
.ide-statusbar .version-info-button { min-height: 24px; padding: 0 4px; border: 0; background: transparent; color: #fff; font-size: inherit; font-weight: 500; }
.ide-statusbar .version-info-button:hover { text-decoration: underline; }
.ide-statusbar .version-info-button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ide-audit-sidebar { position: fixed; inset: var(--title-height) 0 var(--status-height) auto; z-index: 20; width: 320px; display: flex; flex-direction: column; padding: 14px 12px; overflow: hidden; background: var(--panel); border-left: 1px solid var(--border); transition: transform 160ms ease, visibility 160ms ease; }
.audit-sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.audit-sidebar-header h2 { margin: 0; font-size: 14px; letter-spacing: .5px; text-transform: uppercase; }
.audit-sidebar-header button { min-height: 28px; padding: 3px 8px; font-size: 12px; }
.audit-search { width: 100%; margin-top: 12px; }
.audit-sidebar-description { margin: 10px 0; color: var(--muted); font-size: 12px; }
.audit-events { min-height: 0; flex: 1; overflow-y: auto; }
.audit-event { display: grid; gap: 4px; padding: 10px 4px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.audit-event strong { font-size: 13px; font-weight: 600; }
.audit-event-meta { min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.audit-event-subject { min-width: 0; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.audit-event-detail, .audit-event time, .audit-empty { color: var(--muted); font-size: 11px; }
.audit-event time { flex: none; text-align: right; white-space: nowrap; }
.audit-event-detail { font-family: ui-monospace, monospace; }
.audit-empty { margin: 8px 2px; }
.audit-empty.error { color: var(--danger); }
.audit-sidebar-collapsed { --audit-sidebar-width: 0px; }
.audit-sidebar-collapsed .ide-audit-sidebar { visibility: hidden; transform: translateX(100%); }
.version-info-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgb(15 23 42 / 45%); }
.version-info-overlay[hidden] { display: none; }
.version-info-card { width: min(440px, 100%); padding: 20px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface); box-shadow: 0 8px 32px rgb(0 0 0 / 20%); }
.version-info-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.version-info-header h2 { margin: 0; font-size: 18px; }
.version-info-card p:last-child { margin-bottom: 0; }
.sidebar-collapsed .ide-sidebar { visibility: hidden; transform: translateX(-100%); }
.sidebar-collapsed .ide-tabbar { left: 0; }
.sidebar-collapsed .workspace-area { left: 0; }
.sidebar-collapsed .ide-statusbar { left: 0; }

@media (max-width: 700px) {
  :root { --sidebar-width: 210px; --audit-sidebar-width: min(300px, 88vw); --title-height: 52px; --tab-height: 36px; --status-height: 26px; }
  .ide-statusbar { transition: none; }
  .ide-titlebar { gap: 7px; padding: 0 7px; }
  .ide-titlebar > span { display: none; }
  .global-search { min-width: 80px; margin: 0; }
  .global-search input { padding: 4px 6px; font-size: 12px; }
  .global-search-results { left: 12px; width: calc(100vw - 24px); }
  .titlebar-actions { gap: 6px; }
  .theme-control { gap: 4px; }
  .theme-control select { min-width: 66px; padding: 3px; }
  #logout { padding: 4px 7px; }
  .ide-sidebar { box-shadow: 5px 0 16px rgb(0 0 0 / 12%); }
  .ide-audit-sidebar { width: min(300px, 88vw); box-shadow: -5px 0 16px rgb(0 0 0 / 12%); }
  .ide-tabbar, .workspace-area { right: 0; }
  .workspace-section { padding: 16px 12px; }
  .issued { grid-template-columns: 1fr; }
  .issued strong { grid-column: auto; }
  .customer-dialog-actions { flex-wrap: wrap; }
  .customer-dialog-spacer { flex-basis: 100%; }
  .store-dialog-form { grid-template-columns: 1fr; }
  .store-dialog-form > label:first-child, .store-dialog-form > label:nth-child(2),
  .store-dialog-form > label:nth-child(3), .store-dialog-form > p,
  .store-dialog-actions { grid-column: auto; }
  .store-dialog-card { max-height: calc(100vh - 24px); }
  .section-header h2 { font-size: 17px; }
  .login-card { padding: 28px 22px; }
}

@media (max-width: 450px) {
  .ide-statusbar { gap: 6px; padding: 0 8px; }
  .statusbar-context { flex: 1; overflow: hidden; }
  .statusbar-context > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .ide-sidebar, .ide-audit-sidebar, .ide-tabbar, .workspace-area, .ide-statusbar { transition: none; }
}
