:root {
  --ink: #10233d;
  --muted: #607086;
  --line: #dce5ef;
  --surface: #ffffff;
  --surface-soft: #f5f8fc;
  --nav: #08182d;
  --nav-soft: #122b4a;
  --blue: #1479d1;
  --cyan: #21b6e7;
  --blue-soft: #eaf5fd;
  --good: #16784a;
  --good-soft: #e9f7f0;
  --warn: #a45d00;
  --warn-soft: #fff4df;
  --danger: #a42f3a;
  --danger-soft: #fff0f2;
  --shadow: 0 16px 45px rgba(17, 40, 72, 0.08);
  --radius: 18px;
  --sidebar-width: 236px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--surface-soft);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-soft); }
body { margin: 0; min-height: 100vh; background: var(--surface-soft); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(33, 182, 231, 0.35); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(circle at 78% 16%, rgba(33, 182, 231, 0.2), transparent 26rem),
    radial-gradient(circle at 18% 86%, rgba(20, 121, 209, 0.16), transparent 28rem),
    linear-gradient(145deg, #061426, #0b2340 58%, #0b3155);
}
.login-panel {
  width: min(460px, 100%);
  padding: 38px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}
.product-lockup { margin-bottom: 30px; }
.product-kicker { display: block; color: var(--blue); font-weight: 760; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.74rem; }
.product-lockup h1 { margin: 7px 0 8px; font-size: clamp(2.2rem, 7vw, 3.2rem); line-height: 1; letter-spacing: -0.055em; }
.product-lockup p { margin: 0; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 7px; font-size: 0.86rem; font-weight: 720; }
.login-form input {
  width: 100%;
  border: 1px solid #cdd9e7;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  min-height: 48px;
}
.login-form input:focus { border-color: var(--cyan); }
.security-note { margin: 22px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; }
.form-status { min-height: 1.3em; margin: 2px 0 0; color: var(--danger); font-size: 0.86rem; }

.button { border: 0; border-radius: 11px; min-height: 42px; padding: 9px 14px; font-weight: 720; }
.button-primary { margin-top: 10px; min-height: 48px; color: #fff; background: linear-gradient(135deg, var(--blue), #149cd8); box-shadow: 0 8px 24px rgba(20, 121, 209, 0.24); }
.button-primary:hover { filter: brightness(1.04); }
.button-primary:disabled { opacity: 0.6; cursor: wait; }
.button-quiet { color: #dce9f7; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); }
.button-quiet:hover { background: rgba(255,255,255,0.13); }
.icon-button { border: 0; background: transparent; color: inherit; font-size: 1.35rem; padding: 8px; border-radius: 10px; }

.workspace { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: 72px minmax(0, 1fr); }
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  color: #fff;
  background: var(--nav);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.topbar-brand { display: flex; align-items: center; min-width: 0; }
.topbar-brand strong { display: block; font-size: 1.08rem; letter-spacing: -0.025em; }
.topbar-brand span { display: block; color: #9cb1c9; font-size: 0.7rem; margin-top: 1px; }
.nav-toggle { display: none; margin-right: 8px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.organisation-select {
  max-width: 260px;
  min-height: 40px;
  color: #eef7ff;
  background: var(--nav-soft);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 34px 8px 12px;
}
.user-summary { display: grid; justify-items: end; gap: 2px; min-width: 100px; }
#user-name { font-size: 0.82rem; font-weight: 720; color: #e8f2fc; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-pill, .read-only-badge, .count-pill, .status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  white-space: nowrap;
}
.role-pill { padding: 2px 7px; color: #a9c3dd; background: rgba(255,255,255,0.07); font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.07em; }

.sidebar {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px 12px 16px;
  color: #d9e6f4;
  background: #0a1d35;
  border-right: 1px solid rgba(255,255,255,0.05);
}
.nav-list { display: grid; gap: 5px; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 13px;
  border: 0;
  border-radius: 11px;
  color: #b8c9dc;
  background: transparent;
  text-align: left;
  font-weight: 660;
  font-size: 0.9rem;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,0.055); }
.nav-item.active { color: #fff; background: linear-gradient(115deg, rgba(20,121,209,0.34), rgba(33,182,231,0.17)); box-shadow: inset 3px 0 0 var(--cyan); }
.nav-count { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; color: #fff; background: var(--danger); font-size: 0.67rem; }
.sidebar-foot { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; padding: 12px 9px; color: #8da6bf; font-size: 0.75rem; }
.sidebar-foot small { grid-column: 2; margin-top: 2px; color: #657f9c; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #47cc85; box-shadow: 0 0 0 4px rgba(71,204,133,0.11); }

.main-content { grid-column: 2; grid-row: 2; min-width: 0; padding: 28px clamp(20px, 3vw, 42px) 50px; }
.global-status { min-height: 0; margin-bottom: 0; }
.global-status:not(:empty) { margin-bottom: 18px; padding: 12px 14px; border: 1px solid #ffd4d8; border-radius: 11px; color: var(--danger); background: var(--danger-soft); font-size: 0.88rem; }
.view { display: none; max-width: 1500px; margin: 0 auto; }
.view.active { display: block; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 4px 0 22px; }
.page-heading h2 { margin: 3px 0 5px; font-size: clamp(1.65rem, 3vw, 2.25rem); line-height: 1.12; letter-spacing: -0.04em; }
.page-heading p { margin: 0; }
.eyebrow { margin: 0; color: var(--blue); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.075em; text-transform: uppercase; }
.muted { color: var(--muted); }
.read-only-badge { padding: 6px 10px; color: var(--good); background: var(--good-soft); border: 1px solid #c9ead9; font-size: 0.7rem; font-weight: 720; }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.compact-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card {
  min-width: 0;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 7px 24px rgba(17, 40, 72, 0.035);
}
.metric-card span { display: block; color: var(--muted); font-size: 0.77rem; font-weight: 700; }
.metric-card strong { display: block; margin-top: 9px; font-size: clamp(1.25rem, 2.1vw, 1.75rem); letter-spacing: -0.045em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-card small { display: block; margin-top: 8px; color: #8492a3; font-size: 0.7rem; line-height: 1.35; }
.hero-metric { border-color: #b7def7; background: linear-gradient(145deg, #f8fdff, var(--blue-soft)); }
.hero-metric strong { color: #086caf; }

.two-column { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr); gap: 16px; margin-top: 16px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 7px 24px rgba(17, 40, 72, 0.035); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 14px; }
.panel-heading h3, .panel > h3 { margin: 2px 0 0; font-size: 1.02rem; letter-spacing: -0.02em; }
.panel-heading p { margin: 5px 0 0; font-size: 0.78rem; }
.count-pill { min-width: 30px; height: 30px; padding: 0 8px; color: #fff; background: var(--ink); font-size: 0.75rem; font-weight: 800; }
.performance-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; padding: 0 10px 12px; }
.performance-grid > div { padding: 16px 12px; border-top: 1px solid var(--line); }
.performance-grid span { display: block; color: var(--muted); font-size: 0.72rem; }
.performance-grid strong { display: block; margin-top: 7px; font-size: 1.05rem; letter-spacing: -0.025em; }

.attention-list { padding: 0 12px 13px; }
.attention-item { display: grid; grid-template-columns: 9px minmax(0, 1fr); gap: 10px; padding: 12px 10px; border-top: 1px solid var(--line); }
.attention-marker { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--blue); }
.attention-item.urgent .attention-marker { background: var(--danger); }
.attention-item.high .attention-marker { background: var(--warn); }
.attention-item strong { display: block; font-size: 0.84rem; }
.attention-item p { margin: 3px 0 0; color: var(--muted); font-size: 0.74rem; line-height: 1.4; }
.empty-inline { padding: 18px 10px; color: var(--muted); font-size: 0.82rem; border-top: 1px solid var(--line); }

.health-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; overflow: hidden; margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--line); }
.health-strip > div { padding: 16px 18px; background: var(--surface); }
.health-strip span { display: block; color: var(--muted); font-size: 0.7rem; }
.health-strip strong { display: block; margin-top: 5px; font-size: 0.85rem; }

.table-panel { overflow: hidden; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: 0.82rem; }
th { padding: 11px 18px; color: #6a7b8f; background: #f8fafd; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; font-size: 0.67rem; letter-spacing: 0.045em; text-transform: uppercase; }
td { padding: 14px 18px; border-bottom: 1px solid #edf1f6; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th.number, td.number { text-align: right; }
.status-pill { padding: 4px 8px; color: #496177; background: #eef3f7; font-size: 0.68rem; font-weight: 750; text-transform: capitalize; }
.status-pill.good { color: var(--good); background: var(--good-soft); }
.status-pill.warn { color: var(--warn); background: var(--warn-soft); }
.status-pill.danger { color: var(--danger); background: var(--danger-soft); }
.empty-state { padding: 36px 20px; color: var(--muted); text-align: center; font-size: 0.86rem; }
.notice-panel { margin-top: 16px; padding: 20px 22px; }
.notice-panel p { margin: 7px 0 0; color: var(--muted); line-height: 1.55; font-size: 0.86rem; }

.company-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.details-panel { padding: 20px 22px; }
.details-panel h3 { margin: 0 0 16px; }
dl { margin: 0; }
dl > div { display: grid; grid-template-columns: minmax(120px, 0.45fr) minmax(0, 1fr); gap: 18px; padding: 10px 0; border-top: 1px solid var(--line); }
dt { color: var(--muted); font-size: 0.75rem; }
dd { margin: 0; font-size: 0.82rem; font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { padding: 8px 10px; border-radius: 9px; color: #31506e; background: #eef5fb; border: 1px solid #dce9f4; font-size: 0.75rem; font-weight: 700; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 64px minmax(0, 1fr); }
  .topbar { min-height: 64px; padding: 0 12px; gap: 10px; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-brand span { display: none; }
  .user-summary { display: none; }
  .organisation-select { max-width: min(45vw, 230px); }
  .button-quiet { padding-inline: 10px; }
  .sidebar {
    position: fixed;
    top: 64px;
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    height: auto;
    z-index: 25;
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: 22px 0 50px rgba(0,0,0,0.2);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { grid-column: 1; grid-row: 2; padding: 22px 16px 40px; }
  .metric-grid, .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .health-strip { grid-template-columns: repeat(2, 1fr); }
  .company-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .login-panel { padding: 28px 22px; border-radius: 20px; }
  .topbar-actions { gap: 7px; }
  .organisation-select { max-width: 42vw; font-size: 0.78rem; }
  #sign-out { font-size: 0.76rem; }
  .metric-grid, .compact-grid { grid-template-columns: 1fr; }
  .metric-card { padding: 17px; }
  .health-strip { grid-template-columns: 1fr; }
  .performance-grid { grid-template-columns: repeat(2, 1fr); }
  .page-heading { align-items: flex-start; }
  .read-only-badge { display: none; }
  dl > div { grid-template-columns: 1fr; gap: 4px; }
  dd { text-align: left; }
  th, td { padding-inline: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
