/* Keystone IAM */
:root {
  --bg: #eef1f5; --panel: #fff; --panel-2: #f7f9fc; --ink: #1a2230; --muted: #667085; 
  --line: #e3e7ee; --accent: #1f6feb; --accent-ink: #fff; --accent-soft: #e8f0fe;
  --danger: #c0392b; --ok: #1e7e4f; --warn: #9a6400;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .05); --shadow-md: 0 2px 10px rgba(16,24,40,.07);
  --sidebar: #141b2d; --sidebar-ink: #c3cbda; --sidebar-active: #1f6feb;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1117; --panel: #171b22; --panel-2: #1c212b; --ink: #e7eaee; --muted: #9aa4b1; --line: #2a303a;
    --accent: #4f8bf0; --accent-ink: #0b0e12; --accent-soft: #1b2740; --danger: #ff6b6b; --ok: #4cc38a; --warn: #f0b44c;
    --sidebar: #10141d; --sidebar-ink: #aab3c5; }
}
svg { flex: none; vertical-align: -3px; }
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; word-break: break-all; }
pre { overflow-x: auto; font-size: .85rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .big { font-size: 1.3rem; } .nowrap { white-space: nowrap; }
.span { grid-column: 1 / -1; }

input, select, textarea, button, .button {
  font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: .5rem .65rem;
}
input, select, textarea { width: 100%; }
input[type=checkbox] { width: auto; }
textarea { min-height: 2.6rem; }
button, .button { cursor: pointer; display: inline-block; text-decoration: none; background: var(--panel); white-space: nowrap; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.danger { color: var(--danger); border-color: var(--danger); }
.danger-text { color: var(--danger); cursor: pointer; }
.link { border: 0; background: none; color: var(--accent); padding: 0; }
.small-btn { padding: .2rem .5rem; font-size: .85rem; }
label { display: grid; gap: .3rem; font-size: .92rem; }
label.check { display: flex; align-items: center; gap: .45rem; }
.inline-check { display: inline-flex; margin-right: 1rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .5rem; align-items: end; flex-wrap: nowrap; }
.row.wrap { flex-wrap: wrap; }
.row > select, .row > input { flex: 1; }
.narrow { max-width: 28rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .9rem 1.2rem; align-items: start; }
.checks { display: grid; gap: .4rem; }
form.inline { display: inline; }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar nav a { text-decoration: none; }
.brand { font-weight: 650; text-decoration: none; color: var(--ink); }
.brand small { color: var(--muted); font-weight: 500; }
.logo { color: var(--accent); }
.page { max-width: 64rem; margin: 1.5rem auto; padding: 0 1rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; align-items: start; }
.grid2 > .stack > .card { margin-bottom: 0; }
.flash { padding: .7rem .9rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid var(--line); background: var(--panel); }
.flash.ok { border-color: var(--ok); } .flash.error { border-color: var(--danger); color: var(--danger); } .flash.warn { border-color: var(--warn); }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .4rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge.pii { border-color: var(--accent); color: var(--accent); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.list { list-style: none; padding: 0; margin: 0 0 .8rem; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
table.compact td { padding: .3rem .5rem; }
tr.dim td { opacity: .55; }
td.ua { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; }
td input { padding: .3rem .4rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: flex-end; }

/* auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 30rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem; box-shadow: var(--shadow); }
.auth-card .brand { display: block; margin-bottom: 1.2rem; }
.auth-card .card { box-shadow: none; }
.auth-card form + form { margin-top: 1rem; }
.backup { margin-top: 1rem; }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 6px; }
.codes { columns: 2; font-size: 1.05rem; }
.secret-key { user-select: all; }

/* portal */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: 1rem; }
.tile { display: grid; justify-items: center; gap: .5rem; padding: 1.1rem .6rem; text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.tile img { border-radius: 8px; object-fit: contain; }
.tile-letter { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 1.3rem; }

/* admin */
.admin-shell { display: grid; grid-template-columns: 12rem 1fr; min-height: calc(100vh - 3.2rem); }
.sidenav { background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .5rem; display: grid; align-content: start; gap: .1rem; }
/* sidebar link styling lives in the .navitem rules below (dark theme) */
.admin-main { padding: 1.4rem 1.6rem; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: grid; }
.stat span { color: var(--muted); font-size: .85rem; } .stat strong { font-size: 1.6rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: start; margin-bottom: 1rem; }
.search { display: flex; gap: .4rem; flex: 1; min-width: 16rem; }
.crumbs { color: var(--muted); margin-bottom: .5rem; font-size: .9rem; }
.dir { display: grid; grid-template-columns: 15rem 1fr; gap: 1rem; align-items: start; }
.dir-tree { position: sticky; top: 1rem; max-height: calc(100vh - 6rem); overflow: auto; padding: .7rem; }
.tree { list-style: none; margin: 0; padding-left: .9rem; }
.dir-tree > .tree { padding-left: 0; }
.tree li > .tree { display: none; } .tree li.open > .tree { display: block; }
.tree a { text-decoration: none; color: var(--ink); padding: .1rem .3rem; border-radius: 4px; display: inline-block; }
.tree a.sel { background: var(--accent); color: var(--accent-ink); }
.twisty { border: 0; background: none; padding: 0 .2rem; width: 1rem; color: var(--muted); }
.twisty::before { content: "▸"; } .open > .twisty::before { content: "▾"; }
.twisty-spacer { display: inline-block; width: 1.2rem; }
details.pop { position: relative; }
details.pop > summary { list-style: none; }
details.pop > summary::-webkit-details-marker { display: none; }
.popbody { position: absolute; z-index: 5; right: 0; top: 2.6rem; width: 20rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); display: grid; gap: .8rem; }
.tile-edit { border-bottom: 1px dashed var(--line); padding-bottom: .8rem; margin-bottom: .8rem; }

@media (max-width: 760px) {
  .admin-shell, .dir { grid-template-columns: 1fr; }
  .sidenav { display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .dir-tree { position: static; max-height: 16rem; }
}
@media print { .topbar, .sidenav, button, .button { display: none !important; } }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
select[multiple] { min-height: 7rem; }

/* ===== Enterprise console refinements (phase 2.1) ===== */
.topbar { padding: 0 1.1rem; height: 52px; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; letter-spacing: -.01em; }
.brand .logo { color: var(--accent); display: inline-flex; }
.brand-tag { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: .05rem .35rem; }
.topnav { display: flex; gap: .3rem; align-items: center; }
.topnav a, .topnav .link { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .6rem; border-radius: 6px; text-decoration: none; color: var(--muted); font-size: .9rem; }
.topnav a:hover, .topnav .link:hover { background: var(--panel-2); color: var(--ink); }

/* sidebar: dark, icon-led, like enterprise IAM consoles */
.admin-shell { grid-template-columns: 220px 1fr; }
.sidenav { background: var(--sidebar); border-right: 0; padding: .6rem .5rem; gap: 1px; }
.navitem { display: flex; align-items: center; gap: .65rem; padding: .5rem .7rem; border-radius: 7px; color: var(--sidebar-ink); text-decoration: none; font-size: .9rem; }
.navitem svg { opacity: .8; }
.navitem:hover { background: rgba(255,255,255,.06); color: #fff; }
.navitem.active { background: var(--sidebar-active); color: #fff; }
.navitem.active svg { opacity: 1; }
.admin-main { padding: 1.5rem 1.8rem; background: var(--bg); }
.admin-main h1 { display: flex; align-items: center; gap: .5rem; font-size: 1.35rem; letter-spacing: -.01em; }
.h-icon { display: inline-flex; width: 30px; height: 30px; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); border-radius: 7px; }

.card { box-shadow: var(--shadow); border-radius: 10px; }
.card h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: .5rem; margin-bottom: .9rem; }
.flash { display: flex; align-items: center; gap: .5rem; box-shadow: var(--shadow); }
.flash svg { flex: none; }
.flash.ok { color: var(--ok); } .flash.ok svg { color: var(--ok); }

.primary { display: inline-flex; align-items: center; gap: .4rem; box-shadow: var(--shadow); }
.button, button { display: inline-flex; align-items: center; gap: .4rem; }
.topbar .brand { color: var(--ink); }

/* attribute list editor */
.attr-list { display: flex; flex-direction: column; }
.attr-row { display: grid; grid-template-columns: 230px 1fr; gap: 1rem; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.attr-row:last-child { border-bottom: 0; }
.attr-label { display: flex; flex-direction: column; gap: .15rem; font-size: .9rem; }
.attr-label > span:first-child { font-weight: 550; }
.attr-key { font-size: .72rem; color: var(--muted); background: var(--panel-2); padding: 0 .3rem; border-radius: 3px; width: fit-content; }
.attr-label .badge.pii { margin-top: .1rem; }
.attr-control { display: flex; align-items: center; gap: .6rem; }
.attr-control input, .attr-control select, .attr-control textarea { max-width: 420px; }
.attr-hint { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); font-size: .82rem; }
.req { color: var(--danger); }
.form-actions { display: flex; gap: .6rem; align-items: center; margin-top: 1rem; }

/* rules editor */
.rules-table td { padding: .35rem .4rem .35rem 0; border: 0; }
.rules-table th { border: 0; padding-bottom: .2rem; }
.rules-table select, .rules-table input { width: 100%; }
.rules-table { background: transparent; border: 0; }

/* badges a touch softer */
.badge { background: var(--panel-2); }
.badge.pii { display: inline-flex; align-items: center; gap: .2rem; }
.badge.pii svg { width: 11px; height: 11px; }
.tile { box-shadow: var(--shadow); border-radius: 10px; }
.stat { box-shadow: var(--shadow); border-radius: 10px; }
.stat strong { color: var(--accent); }
.tree a svg, .objects a svg { vertical-align: -4px; opacity: .7; margin-right: .15rem; }
.objects a { text-decoration: none; }
.objects a:hover { text-decoration: underline; }

/* ===== Directory drag-and-drop + multi-select ===== */
.objects.selectable tbody tr[data-type] { cursor: grab; }
.objects.selectable tbody tr[data-type]:active { cursor: grabbing; }
.selcol { width: 34px; text-align: center; }
.selcol input { cursor: pointer; }
.objects tbody tr.sel-row { background: var(--accent-soft); }
.objects tbody tr.sel-row td { border-color: var(--accent); }
.dir.dragging .dir-tree { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: var(--radius); }
.dir.dragging { user-select: none; }
[data-drop-ou].drop-hot { background: var(--accent); color: var(--accent-ink) !important; border-radius: 5px; outline: 2px solid var(--accent); }
tr[data-drop-ou].drop-hot td { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.selbar { display: flex; align-items: center; gap: .6rem; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 8px; padding: .5rem .8rem; margin-bottom: .8rem; }
.selbar .selcount { font-weight: 600; }
.selbar .inline { display: inline-flex; align-items: center; gap: .4rem; }
.selbar select { padding: .3rem .5rem; }
.dnd-hint { margin-top: .5rem; }

/* Provisioning step builder */
.step-card{border:1px solid var(--line,#d7dbe0);border-radius:10px;padding:1rem 1.1rem;margin:.75rem 0;background:var(--surface,#fff)}
.step-head{display:flex;align-items:center;gap:.6rem}
.step-num{display:inline-flex;align-items:center;justify-content:center;width:1.7rem;height:1.7rem;border-radius:50%;background:var(--accent,#2f6fed);color:#fff;font-weight:600;font-size:.85rem;flex:0 0 auto}
.step-type{font-weight:600;font-size:1.05rem}
.step-ctrls{margin-left:auto;display:flex;gap:.35rem}
.step-desc{margin:.35rem 0 .6rem}
.step-grid{display:grid;grid-template-columns:1fr 1fr;gap:.75rem 1rem}
.step-grid .fld-label{display:block;font-weight:600;font-size:.85rem;margin-bottom:.25rem}
.step-grid > label{display:block}
.step-grid textarea,.step-grid input[type=text],.step-grid input[type=number],.step-grid select{width:100%}
.step-grid.substep{margin-top:.6rem;grid-template-columns:1fr 1fr;max-width:32rem}
.step-add{display:flex;gap:.5rem;align-items:center;margin-top:.5rem}
.button.small{padding:.2rem .5rem;font-size:.8rem;line-height:1.2}
@media (max-width:640px){.step-grid{grid-template-columns:1fr}}
