:root {
  /* ── Nav ──────────────────────────────────── */
  --nav: #111827;
  --nav-text: rgba(255,255,255,.58);
  --nav-text-hover: rgba(255,255,255,.9);
  --nav-active: #ffffff;
  --nav-border: rgba(255,255,255,.07);

  /* ── Surface ──────────────────────────────── */
  --bg: #f0f2f6;
  --surface: #ffffff;
  --surface-sunken: #f8f9fb;
  --panel: #ffffff;

  /* ── Border ───────────────────────────────── */
  --line: #e3e6ec;
  --line-strong: #c9cdd6;

  /* ── Text ──────────────────────────────────── */
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;

  /* ── Primary brand ─────────────────────────── */
  --primary: #f97316;
  --primary-deep: #ea6c0a;
  --primary-light: #fff7ed;

  /* ── States ────────────────────────────────── */
  --warn: #dc2626;
  --ok-text: #16a34a;
  --ok-bg: #f0fdf4;
  --ok-border: #bbf7d0;
  --err-bg: #fef2f2;
  --err-border: #fecaca;

  /* ── Shadows ───────────────────────────────── */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 3px 8px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12), 0 3px 6px rgba(0,0,0,.05);

  /* ── Radius ────────────────────────────────── */
  --r-xs: 4px;
  --r-sm: 6px;
  --r: 8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: Inter, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4, p { margin-top: 0; }
h2 { font-size: .92rem; margin-bottom: .5rem; font-weight: 700; }
h3 { font-size: .84rem; margin-bottom: .35rem; font-weight: 700; }

/* .shell-top replaced by .app-nav */
.shell-top { display: none; }

/* ── Application Navbar ──────────────────────────── */
.app-nav {
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 1.25rem;
  background: var(--nav);
  box-shadow: 0 1px 0 var(--nav-border), 0 2px 10px rgba(0,0,0,.18);
  position: sticky;
  top: 0;
  z-index: 200;
  gap: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding-right: 1.5rem;
  border-right: 1px solid var(--nav-border);
  flex-shrink: 0;
}

.app-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: linear-gradient(145deg, var(--primary), var(--primary-deep));
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(249,115,22,.4);
}

.app-name {
  display: block;
  color: var(--nav-active);
  font-size: .82rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.app-tagline {
  display: block;
  color: rgba(255,255,255,.3);
  font-size: .6rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-top: 1px;
}

.app-nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0 .5rem;
  gap: 0;
  flex: 1;
}

.app-nav-link {
  display: inline-flex;
  align-items: center;
  height: 52px;
  padding: 0 .9rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--nav-text);
  text-decoration: none;
  position: relative;
  transition: color .12s;
  white-space: nowrap;
  letter-spacing: .005em;
}
.app-nav-link:hover { color: var(--nav-text-hover); }
.app-nav-link.is-active { color: var(--nav-active); }
.app-nav-link.is-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: .7rem;
  right: .7rem;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

.app-nav-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
  padding-left: .85rem;
  border-left: 1px solid var(--nav-border);
  flex-shrink: 0;
}

.nav-user-label {
  font-size: .74rem;
  color: rgba(255,255,255,.48);
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav .btn.ghost {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.78);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--r-sm);
  padding: .2rem .6rem;
  min-height: 28px;
  font-weight: 600;
  font-size: .74rem;
  cursor: pointer;
  transition: background .12s;
}
.app-nav .btn.ghost:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Login page ────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #e9eaed;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(249,115,22,.12) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 110%, rgba(255,255,255,.04) 0%, transparent 50%);
}

/* Old outer brand — brand is now inside the card header */
.login-shell-brand,
.login-shell-logo,
.login-shell-appname,
.login-shell-orgtag { display: none; }

.login-center-card {
  width: min(420px, 100%);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 4px 6px rgba(0,0,0,.12), 0 20px 60px rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.05);
}

.login-card-header {
  background: var(--nav);
  padding: 1.5rem 1.85rem 1.4rem;
  border-bottom: 1px solid var(--nav-border);
}

.login-header-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.login-header-logo {
  width: 42px;
  height: 42px;
  border-radius: var(--r-sm);
  background: linear-gradient(145deg, var(--primary), var(--primary-deep));
  color: #fff;
  font-size: .8rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 12px rgba(249,115,22,.45);
}

.login-header-appname {
  display: block;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.01em;
}

.login-header-orgtag {
  display: block;
  color: rgba(255,255,255,.38);
  font-size: .66rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  margin-top: 3px;
}

.login-card-body {
  padding: 1.75rem 2rem 2rem;
}

.kicker {
  margin: 0 0 .25rem;
  text-transform: uppercase;
  font-size: 0.67rem;
  letter-spacing: 0.1em;
  color: var(--primary);
  font-weight: 700;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin: .1rem 0 .35rem;
  color: var(--ink);
}

.login-subtitle {
  font-size: .85rem;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 1.4rem;
}

h1 { margin: 0.2rem 0 0.3rem; }
.subtitle { margin: 0; color: var(--muted); }

/* ── Shell grid layout ────────────────────────────── */
.shell-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) minmax(360px, 420px);
  gap: 0.85rem;
  padding: 0.85rem 1.25rem 1.25rem;
  align-items: start;
}

#admin-dashboard {
  min-height: 100vh;
}

#admin-dashboard .shell-grid {
  grid-template-columns: 360px 1fr;
}

/* ── Panels ────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1rem 1rem .85rem;
  box-shadow: var(--shadow-sm);
  min-height: 200px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .75rem;
  padding-bottom: .65rem;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.panel-subhead {
  margin: .85rem 0 .5rem;
  padding-top: .65rem;
  border-top: 1px solid var(--line);
}
.panel-subhead h3 {
  margin: 0;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.panel-search {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .65rem;
  padding: .3rem .55rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-sunken);
  transition: border-color .14s, box-shadow .14s;
}
.panel-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(249,115,22,.12);
}
.panel-search-icon {
  color: var(--muted);
  font-size: .8rem;
  flex-shrink: 0;
}
.panel-search input {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: .18rem 0 !important;
  font-size: .8rem !important;
  border-radius: 0 !important;
  flex: 1;
  min-width: 0;
}
.panel-search input:focus { outline: none; }

/* ── Form card ───────────────────────────────────── */
.form-card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .85rem .9rem .8rem;
  background: var(--surface-sunken);
  display: grid;
  gap: .6rem;
}

.form-card h3 {
  margin: 0 0 .35rem;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--line);
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: .44rem .6rem;
  font: inherit;
  font-size: .82rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color .14s, box-shadow .14s;
  line-height: 1.4;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(249,115,22,.14);
}

textarea { resize: vertical; }

/* ── Buttons ────────────────────────────────────── */
.btn {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: .42rem .75rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .82rem;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  transition: background .13s, border-color .13s, box-shadow .13s;
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(249,115,22,.28);
}
.btn.primary:hover { background: var(--primary-deep); box-shadow: 0 2px 6px rgba(249,115,22,.32); }

.btn.ghost {
  background: var(--surface);
  color: var(--ink-2, var(--ink));
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--surface-sunken); border-color: var(--line-strong); }

/* ── Status messages ──────────────────────────────── */
.status {
  margin: .5rem 0 0;
  font-size: .8rem;
  color: var(--muted);
  min-height: 1.2rem;
  line-height: 1.4;
}
.status.error {
  color: var(--warn);
  font-weight: 600;
}
.status.ok {
  color: var(--ok-text);
  font-weight: 600;
}

/* old tree/stack/login-card block replaced by updated versions below */
.stack { display: grid; gap: .55rem; }

.login-card {
  border: 0;
  padding: 0;
  display: grid;
  gap: .6rem;
  background: transparent;
}

.login-card + .login-card {
  margin-top: .85rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}

.login-card h3 {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 0 0 .15rem;
}

.login-card input {
  padding: .54rem .7rem;
  font-size: .86rem;
}

.login-card .btn.primary {
  justify-content: center;
  width: 100%;
  padding: .58rem 1rem;
  font-size: .86rem;
  margin-top: .1rem;
}

#auth-status {
  min-height: 0;
  border-radius: var(--r-sm);
  padding: .42rem .65rem;
  font-size: .8rem;
  transition: all .15s;
  margin-top: .3rem;
}
#auth-status:empty { display: none; }
#auth-status.ok    { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); font-weight: 600; }
#auth-status.error { background: var(--err-bg); border: 1px solid var(--err-border); color: var(--warn); font-weight: 600; }

/* ── Form tabs ───────────────────────────────────────── */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 3px;
  margin-bottom: .65rem;
}

.tab-btn {
  border: 0;
  background: transparent;
  border-radius: var(--r-xs);
  padding: .26rem .62rem;
  font-size: .76rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s, color .12s, box-shadow .12s;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.4;
}
.tab-btn:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.tab-btn[hidden] { display: none; }
.tab-btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}

.tab-pane { display: none; }
.tab-pane.is-active { display: grid; gap: .55rem; }

/* ── Field labels ────────────────────────────────────── */
.field-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: .01em;
  line-height: 1.4;
}

/* ── Btn small variant ───────────────────────────────── */
.btn.sm {
  padding: .22rem .5rem;
  font-size: .74rem;
  min-height: 26px;
}

/* ── Tree view (file-explorer style) ─────────────────── */
.tree-view {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: .35rem;
  max-height: 440px;
  overflow-y: auto;
  background: var(--surface);
  font-size: .8rem;
}
.tree-view:empty::after {
  content: 'No hierarchy yet.';
  display: block;
  padding: .75rem;
  color: var(--muted);
  font-size: .8rem;
}

.simple-list {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: .35rem;
  max-height: 200px;
  overflow: auto;
  background: var(--surface);
}

details.tree-details { display: block; }
details.tree-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  outline: none;
}
details.tree-details > summary::-webkit-details-marker { display: none; }
details.tree-details > summary:focus-visible { outline: none; }

.tree-row.tree-leaf { padding-left: .3rem; }

.tree-children {
  padding-left: 1.1rem;
  border-left: 1px solid var(--line);
  margin-left: .55rem;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .24rem .35rem;
  border-radius: var(--r-xs);
  min-height: 26px;
  transition: background .1s;
}
.tree-row:hover { background: rgba(249,115,22,.07); }

.tree-row .path {
  font-size: .8rem;
  color: var(--ink);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-code {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 400;
  margin-left: .2rem;
}

.tree-action-btn {
  border: 1px solid rgba(249,115,22,.35);
  background: var(--primary-light);
  border-radius: var(--r-xs);
  padding: .16rem .4rem;
  cursor: pointer;
  font-size: .7rem;
  font-weight: 600;
  color: #9a4010;
  font-family: inherit;
  transition: background .12s, box-shadow .12s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tree-action-btn:hover { background: #fce4cc; box-shadow: 0 1px 3px rgba(249,115,22,.2); }

.tree-btns {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .2rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity .12s;
}
.tree-row:hover .tree-btns { opacity: 1; }

.tree-edit-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: .78rem;
  color: var(--muted);
  padding: .15rem .32rem;
  border-radius: var(--r-xs);
  font-family: inherit;
  line-height: 1;
  transition: background .1s, color .1s;
}
.tree-edit-btn:hover {
  background: rgba(249,115,22,.12);
  color: var(--primary);
}

/* Tree type badges */
.tree-tag {
  display: inline-flex;
  align-items: center;
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  text-transform: uppercase;
  flex-shrink: 0;
  white-space: nowrap;
}
.tree-tag.org     { background: #dbeafe; color: #1e40af; }
.tree-tag.branch  { background: #fef9c3; color: #854d0e; }
.tree-tag.project { background: #dcfce7; color: #166534; }
.tree-tag.line    { background: #ede9fe; color: #6d28d9; }
.tree-tag.station { background: #ffedd5; color: #c2410c; }
.tree-tag.device  { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }

/* ── Users data list ─────────────────────────────────── */
.users-list {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow-y: auto;
  background: var(--surface);
  max-height: 260px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .44rem .65rem;
  border-bottom: 1px solid var(--line);
  font-size: .8rem;
  transition: background .1s;
}
.user-row:last-child { border-bottom: 0; }
.user-row:hover { background: var(--surface-sunken); }

.user-name {
  font-weight: 600;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  font-size: .62rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
  white-space: nowrap;
}
.role-badge.super-admin { background: #fee2e2; color: #991b1b; }
.role-badge.admin       { background: #fff7ed; color: #c2410c; }
.role-badge.engineer    { background: #dcfce7; color: #15803d; }

.user-group {
  color: var(--muted);
  font-size: .74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 120px;
}

/* ── Edit modal (native <dialog>) ────────────────────── */
.edit-modal {
  border: none;
  border-radius: var(--r-lg);
  padding: 0;
  width: 400px;
  max-width: calc(100vw - 2rem);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.edit-modal::backdrop {
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(3px);
}
.edit-modal-inner { display: flex; flex-direction: column; }
.edit-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.1rem .65rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-sunken);
}
.edit-modal-title {
  margin: 0;
  font-size: .9rem;
  font-weight: 700;
  color: var(--ink);
}
.edit-modal-fields {
  padding: .9rem 1.1rem .5rem;
  display: grid;
  gap: .55rem;
}
.edit-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .5rem 1.1rem .9rem;
}
#edit-modal-status {
  min-height: 0;
  margin: 0 1.1rem .25rem;
  font-size: .8rem;
  padding: .32rem .55rem;
  border-radius: var(--r-xs);
}
#edit-modal-status:empty { display: none; }
#edit-modal-status.ok    { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); font-weight: 600; }
#edit-modal-status.error { background: var(--err-bg); border: 1px solid var(--err-border); color: var(--warn); font-weight: 600; }

/* ── Panel create status ─────────────────────────────── */
#create-status {
  margin-top: .6rem;
  padding: .35rem .6rem;
  border-radius: var(--r-xs);
  font-size: .8rem;
}
#create-status:empty { display: none; }
#create-status.ok    { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); font-weight: 600; }
#create-status.error { background: var(--err-bg); border: 1px solid var(--err-border); color: var(--warn); font-weight: 600; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1280px) {
  .shell-grid,
  #admin-dashboard .shell-grid {
    grid-template-columns: 1fr;
  }
}

.password-field {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.password-field input {
  flex: 1;
}

.password-toggle {
  white-space: nowrap;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}
