:root {
  --bg: #f3f4f6;
  --bg-pattern: #e7e9ee;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --surface-muted: #eef0f3;
  --fg: #141418;
  --fg-soft: #2d2d34;
  --muted: #667085;
  --line: #e4e7ec;
  --line-strong: #141418;
  --accent: #c23b3b;
  --accent-hover: #a32f2f;
  --accent-soft: rgba(194, 59, 59, 0.1);
  --accent-glow: #c23b3b;
  --signal: #1c7c8c;
  --signal-bright: #3ec6d4;
  --ink: #2a2a31;
  --warn: #d97706;
  --ok: #15803d;
  --soft: #f5f4f0;
  --sidebar-w: 272px;
  --topbar-h: 62px;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Segoe UI Mono", ui-monospace, monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 24, 0.04);
  --shadow-md: 0 6px 16px rgba(20, 20, 24, 0.06);
  --shadow-lg: 0 12px 32px rgba(20, 20, 24, 0.08);
  --shadow-topbar: none;
  --transition: 0.16s ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(880px 340px at 100% 0, rgba(194, 59, 59, .12), transparent 62%),
    radial-gradient(520px 220px at 0 80px, rgba(28, 28, 34, .05), transparent 70%),
    var(--bg);
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.15rem;
  position: sticky;
  top: 0;
  z-index: 50;
  background: #1c1c22;
  color: #fff;
  box-shadow: 0 3px 0 var(--accent);
  border-bottom: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 160px;
  font-weight: 700;
  letter-spacing: .01em;
  color: #fff;
}
.brand-mark {
  width: 34px;
  height: 34px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.brand-logo {
  height: 32px;
  width: auto;
  display: block;
  border-radius: 4px;
}
.brand-name {
  font-size: .92rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.topnav {
  display: flex;
  gap: .25rem;
  flex: 1;
  overflow-x: auto;
  padding: .25rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-pill);
  scrollbar-width: none;
}
.topnav::-webkit-scrollbar { display: none; }

.topnav-link {
  padding: .42rem .85rem;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  color: rgba(255, 255, 255, 0.72);
  transition: background var(--transition), color var(--transition);
}
.topnav-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}
.topnav-link.is-active {
  background: #fff;
  color: var(--fg);
  box-shadow: 0 0 0 1px rgba(194, 59, 59, .35), var(--shadow-sm);
}

.topbar-schematic {
  width: 168px;
  height: 36px;
  flex: 0 0 auto;
  margin-left: .35rem;
  pointer-events: none;
}
.topbar-schematic svg { width: 100%; height: 100%; display: block; }
.sch-trace {
  stroke-dasharray: 7 9;
  animation: sch-flow 6.5s linear infinite;
}
@keyframes sch-flow {
  to { stroke-dashoffset: -64; }
}
@media (prefers-reduced-motion: reduce) {
  .sch-trace { animation: none; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-left: auto;
  flex-shrink: 0;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: .78rem;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  padding: .25rem .55rem .25rem .25rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .02em;
  flex-shrink: 0;
}
.user-chip-text { line-height: 1.2; }
.user-chip-role { color: rgba(255, 255, 255, 0.55); font-size: .7rem; }

.topbar .btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: var(--radius-pill);
}
.topbar .btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.22);
}

.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}
.topbar-menu-btn:hover { background: rgba(255, 255, 255, 0.12); }
.topbar-menu-icon,
.topbar-menu-icon::before,
.topbar-menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  position: relative;
  border-radius: 1px;
}
.topbar-menu-icon::before,
.topbar-menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
}
.topbar-menu-icon::before { top: -6px; }
.topbar-menu-icon::after { top: 6px; }
.topbar-menu-btn.is-open .topbar-menu-icon { background: transparent; }
.topbar-menu-btn.is-open .topbar-menu-icon::before { top: 0; transform: rotate(45deg); }
.topbar-menu-btn.is-open .topbar-menu-icon::after { top: 0; transform: rotate(-45deg); }

.mobile-nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 45;
}
.mobile-nav-backdrop.is-visible { display: block; }
body.modal-open { overflow: hidden; }
body.mobile-nav-open { overflow: hidden; }

/* ── Shell ── */
.shell {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
  gap: 0;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  padding: 1.1rem .85rem;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 16px rgba(20, 20, 24, 0.04);
  position: relative;
}
.sidebar::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 6px;
  pointer-events: none;
  background:
    linear-gradient(var(--accent), var(--accent)) right / 2px 100% no-repeat,
    var(--ink);
}

.main {
  position: relative;
  flex: 1;
  padding: 1.35rem 1.65rem 2.25rem;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
}

.side-title {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin: 0 0 .55rem;
  padding: 0 .35rem;
  font-weight: 700;
}
.side-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .2rem; }
.side-link {
  display: block;
  padding: .48rem .65rem;
  border-radius: var(--radius-sm);
  font-size: .86rem;
  font-weight: 500;
  color: var(--fg-soft);
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.side-link:hover {
  background: var(--surface-soft);
  color: var(--fg);
}
.side-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.side-link.is-locked { color: var(--ok); font-weight: 600; }
.side-link.is-locked:hover,
.side-link.is-locked.is-active {
  background: #dcfce7;
  color: #166534;
}
.side-empty { color: var(--muted); font-size: .85rem; padding: .5rem .65rem; }
.side-filter { margin-bottom: .85rem; }
.side-actions { margin-top: 1rem; display: grid; gap: .45rem; }

/* ── Page ── */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}
.main > .page-head {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: .9rem 1rem .85rem 1.2rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.main > .page-head::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(var(--ink) 0 62%, var(--accent) 62%);
}
.page-head h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -.03em;
  line-height: 1.15;
  position: relative;
  padding-bottom: .4rem;
}
.page-head h1::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 28px;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.page-actions {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  align-items: center;
}
.page-actions form {
  display: inline-flex;
  gap: .35rem;
  align-items: center;
  flex-wrap: wrap;
  width: auto;
  margin: 0;
}
.page-head .page-actions {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: .28rem;
  box-shadow: var(--shadow-sm);
}
.main > .page-head .page-actions {
  background: var(--surface-soft);
  box-shadow: none;
}
.page-actions .btn,
.page-actions .btn-sm,
.page-actions a.btn,
.modal-actions .btn,
.modal-actions .btn-sm {
  min-height: 2.25rem;
  height: 2.25rem;
  padding: 0 .9rem;
  font-size: .82rem;
  line-height: 1;
  white-space: nowrap;
}
.side-actions .btn {
  width: 100%;
  min-height: 2.25rem;
  height: auto;
  padding: .45rem .9rem;
  white-space: normal;
  text-align: center;
}

.search-input {
  padding: .52rem .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-width: 0;
  flex: 1 1 140px;
  font-size: 16px;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus {
  outline: none;
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(20, 20, 24, 0.08);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: #fff;
  padding: .52rem .95rem;
  cursor: pointer;
  font-weight: 600;
  font-size: .84rem;
  border-radius: 10px;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: none;
}
.btn:hover {
  background: var(--fg-soft);
  border-color: var(--fg-soft);
}
.btn-accent,
.page-actions .btn {
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn-accent:hover,
.page-actions .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(20, 20, 24, .12);
}
.btn:active { transform: none; }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}
.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--line);
  box-shadow: none;
}
.btn-ghost:hover {
  background: var(--surface-soft);
  border-color: #d0d5dd;
}

.btn-sm { padding: .32rem .65rem; font-size: .78rem; }
.btn-warn {
  background: var(--warn);
  border-color: var(--warn);
  color: #fff;
}

/* ── Cards & sections ── */
.card-plain {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1rem;
  background-color: var(--surface);
  background-image: linear-gradient(90deg, var(--ink) 0, var(--ink) 52px, var(--accent) 52px 66px, transparent 66px);
  background-size: 100% 3px;
  background-repeat: no-repeat;
  background-position: top left;
  box-shadow: var(--shadow-sm);
}
.section-title {
  display: flex;
  align-items: center;
  margin: 0 0 .85rem;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -.01em;
  padding-left: .7rem;
  border-left: 3px solid var(--accent);
}
.section-title::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-right: .5rem;
  border: 1.5px solid var(--ink);
  transform: rotate(45deg);
  flex: 0 0 auto;
}
.card-plain > .form-grid > div:not(.field) {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink);
  border-radius: 10px;
  padding: .55rem .7rem .6rem;
}
.card-plain > .form-grid > div:not(.field):nth-child(3n) {
  border-left-color: var(--accent);
}
.card-plain > .form-grid > div:not(.field) strong {
  display: block;
  margin-bottom: .12rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: inset 0 3px 0 var(--ink), var(--shadow-sm);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .86rem;
}
table.data th,
table.data td {
  border-bottom: 1px solid var(--line);
  padding: .6rem .75rem;
  text-align: left;
  vertical-align: top;
}
table.data thead th {
  background: var(--ink);
  color: #f4f4f5;
  border-bottom: 2px solid var(--accent);
}
table.data th {
  background: #f4f4f5;
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--line);
}
table.data thead th:first-child { box-shadow: inset 3px 0 0 var(--accent); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background var(--transition); }
table.data tbody tr:nth-child(even):not(.row-green):not(.row-orange):not(.row-red) td { background: #f6f6f7; }
table.data tr:hover td { background: #f1f1f3; }
table.data tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
table.data.table-def-list {
  border-collapse: separate;
  border-spacing: 0 .28rem;
}
table.data.table-def-list th,
table.data.table-def-list td {
  border-bottom: 0;
  vertical-align: middle;
}
table.data.table-def-list th {
  background: #f3f3f5 !important;
  color: var(--ink) !important;
  font-size: .72rem !important;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-radius: 8px 0 0 8px;
}
table.data.table-def-list td {
  background: #fff;
  font-family: var(--mono);
  font-size: .84rem;
  border-radius: 0 8px 8px 0;
  box-shadow: inset 0 0 0 1px var(--line);
}
table.data tr.row-green td { background: #ecfdf3; }
table.data tr.row-orange td { background: #fff7ed; }
table.data tr.row-red td { background: #fef2f2; }
table.data .mono { font-family: var(--mono); font-size: .82rem; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.1rem; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-span-2 { grid-column: span 2; }
.form-span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .32rem; }
.field label {
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field input,
.field select,
.field textarea {
  border: 1px solid var(--line);
  padding: .52rem .65rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.sidebar select {
  width: 100%;
  appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .5rem 2rem .5rem .75rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--fg);
  margin-top: .4rem;
}
.sidebar select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field textarea { min-height: 90px; resize: vertical; }

.check-list {
  display: grid;
  gap: .35rem;
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: .65rem;
  background: var(--surface-soft);
}
.check-list label {
  display: flex;
  gap: .45rem;
  align-items: center;
  font-size: .85rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fg);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.15rem;
  padding: .25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
.tab {
  padding: .5rem 1rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: .84rem;
  border-radius: var(--radius-pill);
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.tab:hover { color: var(--fg); background: var(--surface-soft); }
.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  box-shadow: none;
}

.split-50 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── KPI ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .85rem;
  margin-bottom: 1.15rem;
}
.kpi {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: .85rem 1rem;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
  border-radius: 4px 0 0 4px;
}
.kpi:nth-child(4n+2)::before { background: var(--ink); }
.kpi:nth-child(4n+3)::before { background: var(--accent); }
.kpi:nth-child(4n)::before { background: var(--ink); }
.kpi .label {
  font-size: .68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
}
.kpi .value {
  font-size: 1.15rem;
  font-weight: 800;
  font-family: var(--mono);
  margin-top: .15rem;
}

/* ── Flashes ── */
.flash {
  padding: .72rem 1.15rem;
  font-size: .88rem;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.flash-success {
  background: #ecfdf5;
  color: #065f46;
  border-left: 4px solid var(--ok);
}
.flash-error {
  background: #fef2f2;
  color: #991b1b;
  border-left: 4px solid var(--accent);
}
.flash-info {
  background: #eff6ff;
  color: #1e40af;
  border-left: 4px solid #3b82f6;
}

.readonly-banner {
  padding: .6rem 1.15rem;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  font-size: .88rem;
  color: #92400e;
  font-weight: 600;
}

body.module-readonly form[method="post"] button[type="submit"],
body.module-readonly form[method="post"] input[type="submit"],
body.module-readonly button[data-open-modal],
body.module-readonly .side-actions .btn,
body.module-readonly button.btn-accent:not(.readonly-allow),
body.module-readonly button.btn-warn:not(.readonly-allow) {
  display: none !important;
}
body.module-readonly .is-readonly-disabled {
  pointer-events: none;
  opacity: .45;
}
body.module-readonly button[onclick*="editFrom"],
body.module-readonly button[onclick*="prepareNew"],
body.module-readonly button[onclick*="openUserModal"],
body.module-readonly #detail-edit-btn,
body.module-readonly #detail-delete-form {
  display: none !important;
}

/* ── Modals ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 24, 0.55);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  z-index: 100;
  overflow-y: auto;
}
.modal-backdrop.is-open { display: flex; }
.modal-backdrop.modal-nested { z-index: 200; }

.modal {
  width: min(920px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 1.25rem 1.35rem 1.45rem;
  box-shadow: var(--shadow-lg);
}
.modal-lg { width: min(1100px, 100%); }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.1rem;
  gap: .75rem;
  padding-bottom: .85rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.02em;
}
.modal-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: 1.15rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}
.modal-body { min-width: 0; max-width: 100%; }

/* ── Detail grid ── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem 1.25rem;
}
.detail-grid .full { grid-column: 1 / -1; }
.detail-grid > * { min-width: 0; }
.detail-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .15rem;
  font-weight: 700;
}
.detail-value {
  font-weight: 700;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ── Login ── */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem;
  background: linear-gradient(145deg, #16161c 0%, #2a1215 45%, #991b1b 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(220, 38, 38, 0.35) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.06) 0%, transparent 40%);
  pointer-events: none;
}
.login-brand-inner { position: relative; z-index: 1; max-width: 420px; }
.login-brand-mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 1.5rem;
  backdrop-filter: blur(8px);
}
.login-brand h1 {
  margin: 0 0 .5rem;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
}
.login-brand p {
  margin: 0;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.55;
}
.login-brand-features {
  margin-top: 2.5rem;
  display: grid;
  gap: .85rem;
}
.login-brand-feature {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-size: .88rem;
  color: rgba(255, 255, 255, 0.8);
}
.login-brand-feature-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-glow);
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-box {
  width: min(420px, 92vw);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 2rem 1.75rem;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.login-box h2 {
  margin: 0 0 .25rem;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -.02em;
}
.login-box .login-sub {
  margin: 0 0 1.35rem;
  color: var(--muted);
  font-size: .9rem;
}
.login-box .field { margin-bottom: .85rem; }
.login-box .btn {
  width: 100%;
  margin-top: .65rem;
  padding: .65rem;
  border-radius: var(--radius-md);
}
.login-box .flash-error {
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  border: 1px solid #fecaca;
}

.muted { color: var(--muted); }
.danger-text { color: var(--accent); font-weight: 700; }
.empty-state {
  position: relative;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(var(--ink), var(--ink)) 22px 22px / 16px 1.5px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 29px 15px / 1.5px 16px no-repeat,
    var(--surface);
  box-shadow: var(--shadow-sm);
}

/* Tablet+: tabuľky s triedou table-mobile-cards zostávajú klasická tabuľka so scrollom v .table-wrap */
@media (min-width: 641px) {
  table.data.table-mobile-cards thead { display: table-header-group; }
  table.data.table-mobile-cards tbody { display: table-row-group; }
  table.data.table-mobile-cards tr.data-row,
  table.data.table-mobile-cards tr.table-empty,
  table.data.table-mobile-cards tr.table-message {
    display: table-row;
    border: 0;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  table.data.table-mobile-cards tr.data-row td,
  table.data.table-mobile-cards tr.table-empty td,
  table.data.table-mobile-cards tr.table-message td {
    display: table-cell;
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: .6rem .75rem;
    font-size: .86rem !important;
    max-width: none !important;
  }
  table.data.table-mobile-cards tr.data-row td::before,
  table.data.table-mobile-cards tr.table-empty td::before,
  table.data.table-mobile-cards tr.table-message td::before {
    display: none;
  }
  .table-wrap.table-mobile-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  .table-wrap.table-mobile-wrap table.data.table-mobile-cards {
    min-width: 620px;
  }
}

/* ── Responsive ── */
@media (max-width: 960px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "brand menu user"
      "nav nav nav";
    height: auto;
    min-height: var(--topbar-h);
    padding: .55rem .75rem;
    gap: .55rem .45rem;
    align-items: center;
  }

  .brand { grid-area: brand; min-width: 0; max-width: none; }
  .topbar-menu-btn { grid-area: menu; display: inline-flex; }
  .topbar-right { grid-area: user; margin-left: 0; gap: .35rem; }

  .topnav {
    grid-area: nav;
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: .15rem;
    overflow: visible;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: .45rem 0 .2rem;
    max-height: min(65vh, 420px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: transparent;
    border-radius: 0;
  }
  .topnav.is-open { display: flex; }

  .topnav-link {
    border-radius: var(--radius-sm);
    padding: .7rem .75rem;
    font-size: .9rem;
  }
  .topnav-link.is-active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
  }

  .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-schematic { display: none; }
  .user-chip-text, .user-chip-role { display: none; }
  .user-chip { padding: .15rem; background: transparent; border: 0; }

  .shell { flex-direction: column; }
  .sidebar::after { display: none; }
  .sidebar {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding: .5rem .75rem .6rem;
    box-shadow: none;
    overflow: visible;
  }
  .side-title { margin: .2rem 0 .25rem; }
  .sidebar .side-list {
    display: flex;
    flex-wrap: nowrap;
    gap: .35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: .15rem !important;
    padding-bottom: .1rem;
  }
  .sidebar .side-list li { flex: 0 0 auto; }
  .sidebar .side-link {
    white-space: nowrap;
    padding: .38rem .7rem;
    background: var(--surface-soft);
    border: 1px solid var(--line);
  }
  .sidebar .side-link.is-active { background: var(--accent-soft); }
  .side-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
  .main { padding: 1rem .75rem 1.5rem; min-width: 0; max-width: 100%; }

  .card-plain,
  .page-head,
  .page-actions,
  .kpi-row,
  .tabs,
  .split-50,
  .form-grid,
  .detail-grid,
  .modal,
  .modal-body {
    max-width: 100%;
    min-width: 0;
  }

  .form-grid, .form-grid.cols-3, .form-grid.cols-4, .split-50 { grid-template-columns: 1fr; }
  .form-span-2, .form-span-all { grid-column: auto; }

  .login-page { grid-template-columns: 1fr; }
  .login-brand { padding: 2rem 1.5rem; min-height: auto; }
  .login-brand-features { display: none; }
  .login-brand h1 { font-size: 1.5rem; }

  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 1.2rem; line-height: 1.25; }
  .page-actions { width: 100%; }

  .kpi-row { grid-template-columns: 1fr 1fr; }
  .modal-backdrop { padding: 0; align-items: stretch; justify-content: flex-start; }
  .modal, .modal-lg {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
    align-self: stretch;
    padding: .85rem .9rem 1rem;
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
  }
  .modal-head { flex-wrap: nowrap; align-items: flex-start; border-bottom: 0; padding-bottom: 0; }
  .modal-head h2 { font-size: 1rem; line-height: 1.3; flex: 1 1 auto; min-width: 0; word-break: break-word; padding-right: .5rem; }
  .modal-head .btn { flex-shrink: 0; align-self: flex-start; }
  .modal-actions { flex-wrap: wrap; justify-content: stretch; border-top: 0; padding-top: 0; }
  .modal-actions .btn { flex: 1 1 calc(50% - .25rem); min-width: 0; }
  .modal-actions .btn.btn-accent { flex-basis: 100%; }
  .modal-body { overflow-x: hidden; }

  table.data { font-size: .82rem; min-width: 0; }
  .modal table.data.table-mobile-cards,
  .modal table.data.table-kv,
  .modal table.data.table-def-list { min-width: 0 !important; }
  table.data th, table.data td { padding: .45rem .5rem; }

  table.data.table-kv,
  table.data.table-def-list,
  table.data.calendar-day-matrix {
    min-width: 0 !important;
    width: 100%;
  }

  table.data.table-kv tbody tr {
    display: grid;
    grid-template-columns: 1fr;
    gap: .15rem;
    border-bottom: 1px solid var(--line);
    padding: .45rem 0;
  }
  table.data.table-kv td { border: 0; padding: 0; }
  table.data.table-kv td:first-child { font-weight: 600; font-size: .78rem; color: var(--muted); }

  table.data.table-def-list {
    border-collapse: collapse;
    border-spacing: 0;
  }
  table.data.table-def-list tr {
    display: block;
    border-bottom: 1px solid var(--line);
    padding: .5rem 0;
  }
  table.data.table-def-list th,
  table.data.table-def-list td {
    display: block;
    width: 100%;
    border: 0;
    padding: .12rem 0;
    background: transparent !important;
    color: inherit !important;
    font-weight: 400;
  }
  table.data.table-def-list th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 600;
  }

  .training-row, .training-bulk-head, .training-row.with-actions { grid-template-columns: 1fr !important; }
  .detail-grid { grid-template-columns: 1fr !important; }
  .date-fields-row { grid-template-columns: 1fr !important; }
  .search-bar-wrap { max-width: 100% !important; }
  .side-filter select, .side-filter input { font-size: 16px; }
  .field input, .field select, .field textarea { font-size: 16px; }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-md);
  }
  .tab { white-space: nowrap; flex-shrink: 0; }

  .check-list { max-height: none; }
  .btn { min-height: 40px; }
}

/* Telefón: kartičky namiesto horizontálneho scrollu stránky */
@media (max-width: 640px) {
  .table-wrap.table-mobile-wrap {
    overflow-x: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }
  table.data.table-mobile-cards { border: 0; min-width: 0 !important; width: 100%; }
  table.data.table-mobile-cards thead { display: none; }
  table.data.table-mobile-cards tbody { display: block; }
  table.data.table-mobile-cards tr.data-row {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    margin-bottom: .65rem;
    padding: .7rem .75rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
  }
  table.data.table-mobile-cards tr.data-row.row-green { background: #ecfdf3; border-color: #86efac; }
  table.data.table-mobile-cards tr.data-row.row-orange { background: #fff7ed; border-color: #fdba74; }
  table.data.table-mobile-cards tr.data-row.row-red { background: #fef2f2; border-color: #fca5a5; }
  table.data.table-mobile-cards tr.data-row td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    border: 0;
    padding: .3rem 0;
    max-width: none !important;
    font-size: .88rem !important;
    text-align: right;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  table.data.table-mobile-cards tr.data-row td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    flex: 0 0 5.5rem;
    text-align: left;
    word-break: break-word;
  }
  .modal table.data.table-mobile-cards tr.data-row td::before { flex: 0 0 4.5rem; }
  .modal table.data.table-mobile-cards tr.data-row td { font-size: .85rem !important; }
  table.data.table-mobile-cards tr.data-row td.col-actions,
  table.data.table-mobile-cards tr.data-row td[data-label=""] {
    display: block;
    padding-top: .55rem;
    margin-top: .35rem;
    border-top: 1px solid var(--line);
    text-align: left;
  }
  table.data.table-mobile-cards tr.data-row td.col-actions::before,
  table.data.table-mobile-cards tr.data-row td[data-label=""]::before { display: none; }
  table.data.table-mobile-cards tr.data-row td.col-actions .btn { width: 100%; min-height: 42px; }
  table.data.table-mobile-cards tr.data-row td input,
  table.data.table-mobile-cards tr.data-row td select,
  table.data.table-mobile-cards tr.data-row td textarea { width: 100%; max-width: 100%; }
  table.data.table-mobile-cards tr.data-row td[colspan] { display: block; text-align: left; }
  table.data.table-mobile-cards tr.data-row td[colspan]::before { display: none; }
  table.data.table-mobile-cards tr.table-empty,
  table.data.table-mobile-cards tr.table-message {
    display: block;
    border: 1px dashed var(--line);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: .65rem;
    background: var(--surface);
  }
  table.data.table-mobile-cards tr.table-empty td,
  table.data.table-mobile-cards tr.table-message td {
    display: block;
    border: 0;
    padding: 0;
    text-align: left;
  }
  table.data.table-mobile-cards tr.table-empty td::before,
  table.data.table-mobile-cards tr.table-message td::before { display: none; }

  .calendar-day-matrix-wrap { overflow-x: visible; }
  table.data.calendar-day-matrix thead { display: none; }
  table.data.calendar-day-matrix tbody tr {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    border-bottom: 1px solid var(--line);
    padding: .45rem 0;
  }
  table.data.calendar-day-matrix tbody td {
    border: 0;
    padding: .15rem 0;
    width: calc(50% - .25rem);
    min-width: 0;
  }
  table.data.calendar-day-matrix tbody td:empty { display: none; }
  table.data.calendar-day-matrix select { width: 100%; max-width: 100%; box-sizing: border-box; }

  .status-inline-form { grid-template-columns: 1fr !important; gap: .45rem !important; padding: .75rem !important; }
  table.data:has(.status-inline-form) thead { display: none; }
  table.data:has(.status-inline-form) tbody td[colspan] {
    display: block;
    padding: 0;
    border: 0;
    background: transparent !important;
  }
  table.data:has(.status-inline-form) tbody tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    margin-bottom: .65rem;
    background: var(--surface);
  }
}

@media (max-width: 480px) {
  .kpi-row { grid-template-columns: 1fr; }
  .brand-name { font-size: .78rem; }
  .topbar { padding: .5rem .65rem; }
  .main { padding: .85rem .65rem 1.25rem; }
  .card-plain { padding: .85rem; }
}
