:root {
  --bg: #f5f8fc;
  --bg-strong: #eaf2fb;
  --surface: #ffffff;
  --surface-soft: #f7faff;
  --ink: #071b4c;
  --muted: #61708c;
  --line: #dde6f2;
  --line-strong: #c8d5e6;
  --nav: #ffffff;
  --brand: #071b4c;
  --brand-dark: #04143a;
  --accent: #ff7a1a;
  --accent-2: #ff7a1a;
  --blue: #2563eb;
  --cyan: #11aab7;
  --warn: #a16207;
  --danger: #b42318;
  --ok: #167243;
  --shadow: 0 18px 46px rgba(7, 27, 76, .09);
  --shadow-soft: 0 10px 28px rgba(7, 27, 76, .065);
}

* { box-sizing: border-box; }

html { min-width: 0; }

body {
  margin: 0;
  background: #f5f8fc;
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.42;
  letter-spacing: 0;
  overflow-x: hidden;
}

body.auth-pending .sidebar,
body.auth-pending .tab {
  visibility: hidden;
}

body.auth-locked {
  background: #f5f8fc;
}

body.auth-locked .app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 100vh;
}

body.auth-locked .sidebar,
body.auth-locked .tab {
  display: none !important;
}

body.auth-locked .workspace {
  width: min(1120px, 100%);
  min-height: 100vh;
  display: grid;
  align-content: center;
  margin: 0 auto;
}

body.auth-locked .topbar {
  grid-template-columns: minmax(0, 520px);
  justify-content: center;
  margin: 0 0 14px;
}

body.auth-locked .topbar > div:first-child {
  text-align: center;
}

body.auth-locked .account-toolbar {
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 0;
}

body.auth-locked .account-toolbar #accountSummary,
body.auth-locked .account-toolbar #logoutBtn,
body.auth-locked .account-toolbar .advanced-auth {
  display: none;
}

body.auth-locked .auth-panel {
  display: block;
}

body.auth-locked .login-card {
  padding: 20px;
}

button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { touch-action: manipulation; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 278px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  padding: 18px 14px;
  background: rgba(255, 255, 255, .96);
  color: var(--ink);
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 30px rgba(7, 27, 76, .04);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: grid;
  gap: 5px;
  min-height: 48px;
  margin-bottom: 18px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--line);
}

.brand-logo {
  width: min(186px, 100%);
  height: auto;
  display: block;
  object-fit: contain;
}

.brand-caption,
.brand-lockup small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand-lockup strong { display: block; font-size: 16px; }

.nav-list {
  display: grid;
  gap: 4px;
  max-height: calc(100vh - 102px);
  overflow: auto;
  padding-right: 2px;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #52617b;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 750;
}

.nav-item:hover {
  background: #f0f6ff;
  color: var(--brand-dark);
}

.nav-item.active {
  background: var(--brand);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(7, 27, 76, .16);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 560px);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.topbar > div,
#pageSubtitle,
h1,
h2,
p {
  min-width: 0;
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.help-text {
  max-width: 980px;
  margin: 7px 0 0;
  color: #4f5d6f;
  font-size: 13px;
  line-height: 1.5;
}

.auth-panel {
  display: none;
  width: min(520px, 100%);
  margin: 0 auto 18px;
}

.account-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
}

.login-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow-soft);
}

.login-card strong { font-size: 14px; }
.login-card small,
.advanced-auth summary {
  color: var(--muted);
  font-size: 12px;
}

.language-field { max-width: 240px; }

.oauth-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.account-toolbar span {
  min-width: 0;
  color: #314154;
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.google-auth-button,
.signup-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 8px 12px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 850;
}

.google-auth-button {
  border: 1px solid #d1d5db;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(7, 27, 76, .06);
}

.google-auth-button::before {
  content: "G";
  width: 22px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  margin-right: 8px;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  color: var(--blue);
  background: #fff;
  font-weight: 950;
}

.signup-link {
  color: var(--brand);
  background: #fff7ed;
  border: 1px solid rgba(255, 122, 26, .28);
}

.signup-page {
  min-height: 100vh;
  display: grid;
  background: #f5f8fc;
}

.signup-shell {
  width: min(520px, calc(100% - 28px));
  margin: auto;
  padding: 32px 0;
}

.signup-card {
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.signup-logo {
  width: min(210px, 100%);
  height: auto;
}

.signup-card h1 {
  font-size: 26px;
}

.signup-card small.ok { color: var(--ok); }
.signup-card small.bad { color: var(--danger); }

.signup-form {
  display: grid;
  gap: 10px;
}

.signup-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.signup-divider::before,
.signup-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.login-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.advanced-auth {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.advanced-auth summary {
  cursor: pointer;
  font-weight: 800;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input, textarea, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: rgba(255, 122, 26, .72);
  box-shadow: 0 0 0 3px rgba(255, 122, 26, .14);
}

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  justify-self: start;
  accent-color: var(--accent);
}

textarea {
  min-height: 110px;
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.btn {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 13px;
  cursor: pointer;
  font-weight: 850;
  box-shadow: 0 12px 22px rgba(255, 122, 26, .18);
}

.btn:hover { filter: brightness(1.02); }

.btn.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--brand);
  box-shadow: none;
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab { display: none; }
.tab.active { display: block; }

.operations-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(260px, .9fr));
  gap: 14px;
  margin-bottom: 14px;
}

.operations-card {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 196px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.operations-card.primary {
  background: #fffaf4;
  border-color: rgba(255, 122, 26, .3);
}

.operations-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.operations-card strong {
  font-size: 25px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.operations-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric,
.surface,
.plan-card,
.site-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.metric {
  padding: 15px;
  min-height: 110px;
  display: grid;
  align-content: space-between;
}

.metric span,
.metric small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.metric strong {
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
  color: var(--brand);
}

.layout-two {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
  gap: 14px;
  align-items: start;
}

.surface {
  padding: 16px;
  margin-bottom: 14px;
}

.surface-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid.narrow {
  grid-template-columns: minmax(160px, 260px) minmax(120px, 180px);
  margin-bottom: 10px;
}

.status-output {
  min-height: 0;
  max-height: 360px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 10px;
  border-left: 4px solid var(--blue);
  background: var(--surface-soft);
  color: #31415f;
  font-size: 13px;
  line-height: 1.45;
}

.status-output[data-empty="1"] { display: none; }
.status-output.ok { border-left-color: var(--ok); }
.status-output.bad { border-left-color: var(--danger); }

.status-output strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.status-output ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.status-output li + li {
  margin-top: 3px;
}

.status-board {
  display: grid;
  gap: 8px;
}

.onboarding-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.module-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffaf4;
}

.module-summary span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.module-summary strong {
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--brand);
  color: #ffffff;
  text-transform: uppercase;
  font-size: 12px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.module-card {
  display: grid;
  gap: 9px;
  min-height: 168px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.module-card.disabled {
  background: #f8fafc;
}

.module-card > div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.module-card strong,
.module-card p {
  overflow-wrap: anywhere;
}

.module-card p {
  margin: 0;
  font-size: 13px;
}

.switch-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  color: var(--ink);
}

.switch-line input {
  width: 20px;
  min-height: 20px;
  flex: 0 0 auto;
}

.onboarding-step {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  min-height: 134px;
}

.onboarding-step span {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
}

.onboarding-step strong {
  display: block;
  margin-bottom: 5px;
}

.onboarding-step p {
  margin: 0;
  font-size: 13px;
}

.check-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--line);
}

.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }
.dot.warn { background: var(--warn); }

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef4ff;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.command-grid button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  padding: 9px 10px;
  font-weight: 800;
  color: var(--brand);
  box-shadow: 0 8px 18px rgba(7, 27, 76, .045);
}

.command-grid button:hover,
.screen-link:hover {
  border-color: rgba(255, 122, 26, .42);
  background: #fffaf4;
  color: #a84a06;
}

.timeline-editor {
  display: grid;
  gap: 8px;
}

.event-row {
  display: grid;
  grid-template-columns: 90px 190px minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.event-row button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.room-preview {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, .7fr);
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f7faff;
  color: var(--ink);
}

.room-stage {
  display: grid;
  place-items: center;
  min-height: 360px;
  background: #071b4c;
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  padding: 16px;
}

.room-side {
  display: grid;
  align-content: space-between;
  gap: 14px;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: #fff;
}

.room-side button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--accent-2);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.plan-list,
.site-list,
.settings-list,
.custom-page-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.plan-card,
.site-card {
  padding: 12px;
  display: grid;
  gap: 9px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.screen-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.screen-link {
  display: block;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-weight: 800;
}

.screen-link::after {
  content: " ->";
  color: var(--accent);
}

.custom-page-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.custom-page-item a {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.diagnostic-components,
.diagnostic-load,
.risk-list,
.diagnostic-guide {
  display: grid;
  gap: 10px;
}

.diagnostic-components { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.diagnostic-load,
.diagnostic-guide { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.diagnostic-card,
.load-card,
.risk-item,
.diagnostic-guide article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.diagnostic-card.ok {
  border-color: rgba(22, 114, 67, .28);
  background: #f7fcf9;
}

.diagnostic-card.warning,
.risk-item.warning {
  border-color: rgba(161, 98, 7, .35);
  background: #fffaf0;
}

.diagnostic-card.critical,
.risk-item.critical {
  border-color: rgba(180, 35, 24, .35);
  background: #fff7f6;
}

.diagnostic-card-head,
.risk-item > div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.diagnostic-card p,
.risk-item p,
.load-card small,
.diagnostic-guide p {
  margin: 6px 0 0;
  font-size: 13px;
}

.load-card span,
.diagnostic-details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.load-card strong {
  display: block;
  margin-top: 5px;
  font-size: 22px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.diagnostic-details {
  display: grid;
  gap: 5px;
  margin: 10px 0 0;
}

.diagnostic-details div {
  display: grid;
  grid-template-columns: minmax(86px, .45fr) minmax(0, 1fr);
  gap: 8px;
}

.diagnostic-details dt,
.diagnostic-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.diagnostic-details dd {
  color: #334155;
  font-size: 12px;
}

.empty-state {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  background: #f7faff;
  text-transform: uppercase;
  letter-spacing: 0;
}

.feature-hidden { display: none !important; }

@media (max-width: 1180px) {
  .operations-panel,
  .layout-two {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: sticky;
    z-index: 30;
    height: auto;
    display: grid;
    gap: 10px;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-lockup {
    min-height: auto;
    margin: 0;
    padding: 0;
    border-bottom: 0;
  }

  .brand-logo { width: 150px; }
  .brand-caption { display: none; }

  .nav-list {
    display: flex;
    gap: 5px;
    max-height: none;
    overflow: auto;
    padding: 0 0 2px;
    overscroll-behavior-x: contain;
  }

  .nav-item {
    width: auto;
    white-space: nowrap;
  }

  .login-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .form-grid,
  .operations-panel,
  .plan-list,
  .site-list,
  .settings-list,
  .custom-page-list,
  .room-preview,
  .screen-grid,
  .onboarding-steps,
  .diagnostic-components,
  .diagnostic-load,
  .diagnostic-guide {
    grid-template-columns: 1fr;
  }

  .module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .room-side { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .workspace {
    padding: 14px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
  }

  .metric-grid,
  .module-grid,
  .module-summary {
    grid-template-columns: 1fr;
  }

  .surface,
  .metric,
  .login-card {
    box-shadow: none;
  }

  .surface { padding: 13px; }
  .surface-head { display: grid; align-items: stretch; }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button-row .btn,
  .command-grid button {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .check-row {
    grid-template-columns: 18px minmax(0, 1fr);
  }

  .check-row .tag {
    grid-column: 2;
    justify-self: start;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .diagnostic-details div { grid-template-columns: 1fr; }

  .event-row { grid-template-columns: 76px minmax(0, 1fr); }
  .event-row textarea,
  .event-row button { grid-column: 1 / -1; }

  h1 { font-size: 23px; }

  input, textarea, select, .btn {
    min-height: 44px;
  }

  .status-output { max-height: 300px; }
  .room-stage { min-height: 220px; }
}

@media (max-width: 440px) {
  .workspace { padding: 12px; }
  .sidebar { padding: 9px 10px; }
  .brand-logo { width: 134px; }
  .nav-item { min-height: 40px; padding: 8px 10px; }
}
