/**
 * Shared admin shell — portfolio / SC chrome (skill §12–14).
 * Tokens: light only (no theme switching).
 * Independent scroll: sidebar nav vs main column (webcontent shell parity).
 * Alias --bg/--panel/--rail etc. for legacy module CSS.
 */
:root {
  color-scheme: light;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-muted: #f1f5f9;
  --color-sidebar: #0f172a;
  --color-sidebar-text: #cbd5e1;
  --color-sidebar-active: #1e293b;
  --color-sidebar-hover: rgba(30, 41, 59, 0.75);
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-border: #e2e8f0;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-accent-soft: #eff6ff;
  --color-topbar: #ffffff;
  --color-danger: #e11d48;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-info: #64748b;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --radius: 0.75rem;
  --font-sans: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-width: 256px;
  --z-toast: 70;

  /* Legacy aliases used by module CSS */
  --bg: var(--color-bg);
  --panel: var(--color-surface);
  --rail: var(--color-sidebar);
  --rail-hover: var(--color-sidebar-active);
  --line: var(--color-border);
  --text: var(--color-text);
  --muted: var(--color-muted);
  --accent: var(--color-accent);
  --accent-2: var(--color-accent-hover);
  --danger: var(--color-danger);
  --warn: var(--color-warning);
  --green: var(--color-success);
  --font: var(--font-sans);
  --mono: var(--font-mono);
  --blue: #3b82f6;
  --amber: #f59e0b;
  --red: #e11d48;
  --on-track: #10b981;
  --ahead: #3b82f6;
  --at-risk: #f59e0b;
  --delayed: #f43f5e;
  --critical: #e11d48;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 14px;
  line-height: 1.45;
}

body.admin-login {
  overflow: auto;
  background: var(--color-bg);
}

a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* —— Shell layout (independent scroll) —— */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  width: 100%;
}

.rail {
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border-right: 1px solid #1e293b;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.15rem 1.25rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}
.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, #3b82f6, #4f46e5);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-name {
  color: #fff;
  font-weight: 700;
  font-size: 0.875rem;
  letter-spacing: 0.01em;
}
.brand-sub {
  font-size: 0.6875rem;
  color: #64748b;
}

.rail-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 0.75rem 1rem;
}

.rail-link,
.rail-item,
.rail-nav a {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  border: 0;
  background: transparent;
  color: var(--color-sidebar-text);
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}
.rail-link {
  margin-bottom: 0.15rem;
}
.rail-link:hover,
.rail-item:hover,
.rail-nav a:hover {
  background: var(--color-sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.rail-link.active,
.rail-item.active,
.rail-nav a.active {
  background: var(--color-sidebar-active);
  color: #fff;
}
.rail-item .ic,
.rail-link .ic {
  width: 1rem;
  text-align: center;
  opacity: 0.85;
  flex-shrink: 0;
}

.rail-group {
  margin-top: 0.85rem;
}
.rail-section {
  padding: 0 0.75rem 0.35rem;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #64748b;
  text-transform: uppercase;
}

.rail-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.rail-footer .muted {
  color: #64748b;
  font-size: 0.7rem;
}

.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--color-bg);
}

.topbar {
  flex-shrink: 0;
  min-height: 4.5rem;
  background: var(--color-topbar);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  flex-wrap: wrap;
}
.topbar-left {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.title-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.topbar h1,
.page-head h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}
.topbar p,
.page-head p {
  margin: 0.15rem 0 0;
  color: var(--color-muted);
  font-size: 0.8125rem;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.today-date {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 0.5rem;
  padding: 0.45rem 0.75rem;
}

.workspace,
.main-col > main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.25rem 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* page-head used as in-content header when not using topbar title */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0;
}

/* —— Shared content primitives —— */
.btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 0.5rem;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover {
  background: var(--color-surface-muted);
}
.btn.outline {
  background: var(--color-surface);
}
.btn.primary {
  background: #0f172a;
  color: #fff;
  border-color: #0f172a;
}
.btn.primary:hover {
  background: #1e293b;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-muted);
}
.btn.danger {
  color: var(--color-danger);
  border-color: color-mix(in srgb, var(--color-danger) 35%, var(--color-border));
}
.btn.small {
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.icon {
  width: 2.2rem;
  padding-left: 0;
  padding-right: 0;
  text-align: center;
}

select,
.toolbar select,
.toolbar input,
.grid input,
.grid select,
.grid textarea {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: 0.5rem;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.8125rem;
  max-width: 100%;
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem 1.25rem;
  box-shadow: var(--shadow-sm);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  gap: 0.75rem;
}
.panel-head h2,
.panel h2,
.panel h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
th,
td {
  text-align: left;
  padding: 0.7rem 0.65rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
th {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-muted);
  font-weight: 600;
}
td.empty,
.empty {
  color: var(--color-muted);
  text-align: center;
  padding: 1.5rem !important;
}
.mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.muted {
  color: var(--color-muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem 1rem;
}
.grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--color-muted);
}
.grid .span-2 {
  grid-column: span 2;
}
.form-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}
.row-actions {
  display: flex;
  gap: 0.35rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}
.toolbar label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--color-muted);
  font-weight: 500;
}
.toolbar-panel {
  padding-bottom: 1rem;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: var(--z-toast);
  background: #0f172a;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  max-width: 360px;
  font-size: 0.8125rem;
  box-shadow: var(--shadow-md);
}
.toast.error {
  background: var(--color-danger);
}
.toast[hidden] {
  display: none !important;
}

/* Login (no rail) */
.login-shell {
  max-width: 420px;
  margin: 4rem auto;
  padding: 0 1rem 3rem;
}
.login-shell .panel {
  margin-top: 1rem;
}

.spa-link {
  color: #94a3b8 !important;
  font-size: 0.75rem !important;
  text-decoration: none !important;
}
.spa-link:hover {
  color: #fff !important;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  html,
  body {
    height: auto;
    overflow: auto;
  }
  .rail {
    height: auto;
    max-height: 40vh;
  }
  .main-col {
    height: auto;
    overflow: visible;
  }
  .workspace,
  .main-col > main {
    overflow: visible;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .grid .span-2 {
    grid-column: span 1;
  }
}

/* —— Embedded as a tab in the SPA shell: shell owns the left nav —— */
html.sc-embedded .shell {
  grid-template-columns: 1fr;
}

html.sc-embedded .rail {
  display: none;
}
