:root {
  /* NachoDesk palette: corn-chip cream, toasted brown, corn yellow */
  --bg: #f8f3e9;
  --surface: #fffcf6;
  --surface-2: #f2eadb;
  --border: #e3d6bf;
  --text: #2a1f14;
  --muted: #6f5e49;
  --accent: #a14f18;
  --accent-text: #ffffff;
  --accent-soft: #f7e6cf;
  --corn: #80600c;
  --danger: #b3392b;
  --danger-soft: #f8e2dc;
  --ok: #4f7a1f;
  --shadow: 0 1px 2px rgb(60 40 15 / 7%), 0 4px 16px rgb(60 40 15 / 7%);
  --overlay: rgb(35 24 12 / 55%);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18130e;
    --surface: #211a13;
    --surface-2: #2b2219;
    --border: #3b2f23;
    --text: #f3eadb;
    --muted: #b5a48c;
    --accent: #eaa45f;
    --accent-text: #1e150c;
    --accent-soft: #3a2817;
    --corn: #e8c46a;
    --danger: #f07b6b;
    --danger-soft: #3c1f1a;
    --ok: #a8cf6f;
    --shadow: 0 1px 2px rgb(0 0 0 / 35%), 0 4px 16px rgb(0 0 0 / 30%);
    --overlay: rgb(8 5 2 / 65%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* `hidden` must win over display rules such as .field { display: flex } */
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Layout --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-weight: 650; color: var(--text); text-decoration: none; }
.brand { font-size: 18px; letter-spacing: -.01em; gap: 8px; }
.brand-accent { color: var(--accent); }
.brand-mark { width: 22px; height: 22px; background: url("favicon.svg") center / contain no-repeat; flex: none; }
.brand-mark-lg { width: 56px; height: 56px; display: block; margin: 0 auto; }
.login-brand { margin-bottom: 4px; }
.nav-user { color: var(--muted); padding: 0 8px; font-weight: 500; }
.lang-select { width: auto; padding: 5px 8px; font-size: 13px; color: var(--muted); background: transparent; }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav-link { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 8px 0 20px; flex-wrap: wrap; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

/* --- Forms --- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.field small { color: var(--muted); font-size: 12px; }
input:not([type=checkbox]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 0; }
.search { max-width: 320px; }
.grid-2, .grid-3 { display: grid; gap: 14px 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.checklist {
  max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; background: var(--surface-2);
}
.advanced summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13px; margin-bottom: 8px; }

.btn {
  font: inherit; font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sso { background: var(--accent-soft); border-color: var(--accent); color: var(--text); padding: 9px 14px; }
.btn-sso:hover { background: var(--accent-soft); filter: brightness(.97); }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* --- Login --- */
.login-wrap { display: grid; place-items: center; min-height: 70vh; }
.login { width: min(380px, 100%); padding: 28px; }
.login h1 { text-align: center; }

/* --- Two-factor authentication --- */
.qr-wrap { display: grid; place-items: center; }
.qr { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); }
.manual-key summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.manual-key code { display: block; margin-top: 6px; font-size: 14px; letter-spacing: .05em; word-break: break-all; user-select: all; }
.code-input { font: 600 22px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .15em; text-align: center; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; text-align: center; }
.link-button:hover { text-decoration: underline; }
.recovery-codes { columns: 2; column-gap: 24px; margin: 0; padding: 12px 12px 12px 32px; background: var(--surface-2); border-radius: 8px; }
.recovery-codes li { padding: 2px 0; }
.recovery-codes code { font-size: 14px; }
.row-actions.row-actions-start { justify-content: flex-start; }

/* --- Account page --- */
.panels { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.panel { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0; }
.panel > .btn { align-self: flex-start; }
.panel h3 { margin: 8px 0 0; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--border); }
.setting .muted { margin-top: 4px; }
.notice { margin: 0; padding: 8px 12px; border-radius: 8px; background: var(--accent-soft); }

/* --- Connections --- */
.groups { display: flex; flex-direction: column; gap: 28px; }
.group-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.group-head p { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tile {
  display: flex; align-items: center; gap: 12px; padding: 14px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile-icon {
  flex: none; width: 38px; height: 30px; border-radius: 6px; background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent); position: relative;
}
.tile-icon::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -6px; height: 3px; border-radius: 2px; background: var(--accent); }
.tile-body { display: flex; flex-direction: column; min-width: 0; }
.tile-body small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Administration --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 550; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-proto { font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; }
.badge-proto-vnc { color: var(--corn); border-color: var(--corn); background: transparent; }
.tile .badge-proto { margin-left: auto; align-self: flex-start; }
.badge-source-ldap, .badge-source-oidc { border-color: var(--accent); color: var(--accent); background: transparent; }
code.mapping { font-size: 12px; word-break: break-all; }

/* --- Dialogs & toasts --- */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: min(460px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
.dialog-wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: var(--overlay); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { padding: 10px 16px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); max-width: 420px; }
.toast-error { background: var(--danger); color: #fff; }

@media (max-width: 720px) {
  .container { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .search { max-width: none; }
}

/* --- RDP client --- */
body.client { background: #000; overflow: hidden; }
.display { position: fixed; inset: 0; outline: none; overflow: hidden; }
.session-view { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
body.client.native .session-view { display: block; overflow: auto; }
.guac-display { cursor: none; }
.guac-display canvas { image-rendering: auto; }

.menu-handle {
  position: fixed; top: 0; left: 50%; transform: translate(-50%, -14px); z-index: 20;
  width: 64px; height: 24px; border: 0; border-radius: 0 0 10px 10px; cursor: pointer;
  background: rgb(42 31 20 / 88%); transition: transform .15s;
}
.menu-handle:hover, .menu-handle:focus-visible { transform: translate(-50%, 0); }
.menu-handle-count {
  position: absolute; top: 4px; right: 6px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font: 700 10px/15px system-ui, sans-serif;
}
.menu-handle span { display: block; width: 22px; height: 3px; margin: 10px auto 0; border-radius: 2px; background: #f0d9a8; box-shadow: 0 -5px 0 #f0d9a8; }

.menu {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(340px, 100vw); z-index: 30;
  background: var(--surface); color: var(--text); border-left: 1px solid var(--border);
  box-shadow: -10px 0 40px rgb(0 0 0 / 35%); padding: 16px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 20px;
}
.menu[hidden] { display: none; }
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu section { display: flex; flex-direction: column; gap: 8px; }
.menu section p { margin: 0; }
.menu-foot { margin-top: auto; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* --- Session switcher --- */
.session-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.session-list:empty { display: none; }
.session-item { display: flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.session-item.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.session-select { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.session-thumb { width: 80px; height: 50px; border-radius: 4px; background: #000; flex: none; }
.session-meta { display: flex; flex-direction: column; min-width: 0; }
.session-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-name kbd { font: 600 10px/1 ui-monospace, monospace; padding: 2px 4px; margin-right: 6px; border: 1px solid var(--border); border-radius: 3px; color: var(--muted); }
.session-state { font-size: 12px; color: var(--muted); }
.session-state::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: var(--muted); vertical-align: 1px; }
.state-connected::before { background: var(--ok); }
.state-connecting::before, .state-idle::before { background: var(--corn); }
.state-error::before, .state-closed::before { background: var(--danger); }
.session-close { padding: 4px 8px; }
.connection-picker { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; }
.picker-item { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.picker-item:hover { border-color: var(--accent); }
.picker-item > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.picker-badges { display: flex; gap: 4px; flex: none; }

.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: var(--overlay);
}
.overlay[hidden] { display: none; }
.overlay-card { padding: 28px; width: min(440px, 100%); text-align: center; }
.overlay-card .actions { justify-content: center; margin-top: 16px; }
.spinner {
  width: 32px; height: 32px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
