:root {
  --navy-950: #07182d;
  --navy-900: #102f56;
  --navy-800: #173f6d;
  --blue-600: #0b72d0;
  --blue-500: #1689ee;
  --blue-100: #e8f3ff;
  --cyan-400: #30c3e6;
  --ink: #16263a;
  --muted: #66768a;
  --line: #dce5ee;
  --surface: #ffffff;
  --canvas: #f4f7fa;
  --green: #19a974;
  --amber: #e9a317;
  --orange: #ec6b2d;
  --red: #d63d45;
  --purple: #7b4bc6;
  --shadow: 0 8px 30px rgba(18, 47, 82, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 72px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 26px;
  color: #fff;
  background: linear-gradient(105deg, var(--navy-950), var(--navy-900) 66%, #174978);
  box-shadow: 0 6px 20px rgba(6, 23, 45, .18);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  flex: 0 0 auto;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 9px 2px 9px 2px;
  background: linear-gradient(145deg, var(--cyan-400), var(--blue-600));
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.1);
}
.brand-mark span { font-size: 21px; font-weight: 800; transform: skew(-8deg); }
.brand-copy { display: grid; line-height: 1; letter-spacing: .08em; }
.brand-copy strong { font-size: 18px; }
.brand-copy small { margin-top: 4px; font-size: 9px; letter-spacing: .36em; opacity: .72; }
.topbar-context { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.context-title { font-weight: 700; }
.context-subtitle { color: #b9cae0; font-size: 14px; }
.context-separator { width: 1px; height: 24px; background: rgba(255,255,255,.2); }
.topbar-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.search {
  width: min(390px, 34vw);
  height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px 0 13px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 9px;
  background: rgba(255,255,255,.1);
}
.search input { width: 100%; border: 0; outline: 0; color: #fff; background: transparent; font-size: 14px; }
.search input::placeholder { color: #b7c8dc; }
.search kbd { padding: 2px 6px; color: #bbcee3; border: 1px solid rgba(255,255,255,.18); border-radius: 5px; font-size: 11px; }
.icon-button, .profile {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
}
.icon-button { border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.08); }
.icon-button:hover { background: rgba(255,255,255,.16); }
.profile { background: #fff; color: var(--navy-900); font-size: 12px; font-weight: 800; }

.app-shell { max-width: 1580px; margin: 0 auto; padding: 30px 32px 110px; }
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 25px;
}
.eyebrow { margin-bottom: 7px; color: var(--blue-600); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.live-dot { width: 8px; height: 8px; display: inline-block; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(25,169,116,.12); }
.eyebrow-separator { margin: 0 6px; color: #a4b1bf; }
h1 { margin: 0; color: var(--navy-900); font-size: clamp(28px, 3vw, 42px); letter-spacing: -.04em; line-height: 1.12; }
.page-heading p { margin: 8px 0 0; color: var(--muted); }
.heading-actions, .toolbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.save-indicator { display: inline-flex; align-items: center; gap: 7px; margin-right: 4px; color: var(--muted); font-size: 13px; }
.save-indicator i { width: 7px; height: 7px; border-radius: 50%; background: #9aa9b9; }
.save-indicator.saved i { background: var(--green); }
.button {
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  transition: .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--blue-600); box-shadow: 0 6px 18px rgba(11,114,208,.18); }
.button.secondary { color: var(--navy-900); border-color: var(--line); background: #fff; }
.button.ghost { color: #fff; border-color: rgba(255,255,255,.28); background: transparent; }
.button.light { color: var(--navy-900); background: #fff; }

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 -2px 20px;
  padding: 0 2px 10px;
  overflow-x: auto;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--line);
}
.tab {
  min-height: 40px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 14px;
  font-weight: 650;
}
.tab:hover { color: var(--navy-900); background: #eaf0f6; }
.tab.active { color: #fff; background: var(--navy-900); }
.tab b { min-width: 23px; padding: 2px 6px; border-radius: 20px; background: rgba(255,255,255,.13); font-size: 11px; }
.tab:not(.active) b { color: var(--blue-600); background: var(--blue-100); }

.toolbar {
  min-height: 66px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 14px;
}
.toolbar h2 { margin: 0; color: var(--navy-900); font-size: 19px; letter-spacing: -.02em; }
.toolbar p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  min-height: 34px;
  padding: 0 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}
.chip.active { color: var(--blue-600); border-color: #a9d3f6; background: var(--blue-100); }
.add-button { display: none; }
.editing .add-button { display: inline-block; }

.content { min-height: 420px; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric-card {
  position: relative;
  min-height: 128px;
  padding: 20px;
  overflow: hidden;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.metric-card::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue-500); }
.metric-card.alert::after { background: var(--amber); }
.metric-card.dark { color: #fff; border-color: var(--navy-900); background: linear-gradient(140deg, var(--navy-900), #1d527f); }
.metric-card.dark::after { background: var(--cyan-400); }
.metric-label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.metric-card.dark .metric-label { color: #b8d3ed; }
.metric-value { display: block; margin-top: 7px; font-size: 34px; font-weight: 800; letter-spacing: -.05em; line-height: 1; }
.metric-detail { display: block; margin-top: 9px; color: var(--muted); font-size: 12px; }
.metric-card.dark .metric-detail { color: #c9def1; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, .7fr); gap: 16px; }
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; color: var(--navy-900); font-size: 16px; }
.panel-header span { color: var(--muted); font-size: 12px; }
.alert-ladder { padding: 22px 22px 25px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; }
.alert-level { position: relative; padding: 7px 10px 0 0; }
.alert-level::before { content: ""; display: block; width: 100%; height: 7px; margin-bottom: 13px; background: currentColor; }
.alert-level:first-child::before { border-radius: 8px 0 0 8px; }
.alert-level:last-child::before { border-radius: 0 8px 8px 0; }
.alert-level.yellow { color: var(--amber); }
.alert-level.orange { color: var(--orange); }
.alert-level.red { color: var(--red); }
.alert-level.purple { color: var(--purple); }
.alert-level strong { display: block; color: var(--navy-900); font-size: 18px; }
.alert-level span { color: var(--muted); font-size: 12px; }
.route-list { margin: 0; padding: 8px 20px 20px; list-style: none; }
.route-list li { position: relative; min-height: 60px; padding: 12px 0 12px 38px; border-bottom: 1px solid #edf1f5; }
.route-list li:last-child { border-bottom: 0; }
.route-list li::before { content: attr(data-step); position: absolute; left: 0; top: 14px; width: 24px; height: 24px; display: grid; place-items: center; color: #fff; border-radius: 7px; background: var(--navy-900); font-size: 11px; font-weight: 800; }
.route-list strong { display: block; color: var(--navy-900); font-size: 13px; }
.route-list span { color: var(--muted); font-size: 12px; }

.data-panel { border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow: auto; max-height: calc(100vh - 320px); min-height: 390px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
thead { position: sticky; top: 0; z-index: 3; }
th {
  padding: 14px 13px;
  color: #e9f3fc;
  background: var(--navy-900);
  border-right: 1px solid rgba(255,255,255,.08);
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .035em;
  text-transform: uppercase;
}
th:first-child { padding-left: 18px; }
td { min-width: 125px; max-width: 280px; padding: 13px; vertical-align: top; border-bottom: 1px solid #e9eef3; color: #334458; background: #fff; }
td:first-child { padding-left: 18px; }
tbody tr:nth-child(even) td { background: #f9fbfd; }
tbody tr:hover td { background: #f0f7fd; }
.cell-primary { color: var(--navy-900); font-weight: 700; }
.cell-id { min-width: 54px; width: 54px; color: var(--blue-600); font-weight: 800; }
.cell-small { min-width: 90px; max-width: 140px; }
.cell-wide { min-width: 250px; }
.row-action { min-width: 54px; width: 54px; text-align: center; }
.delete-row { width: 28px; height: 28px; color: var(--red); border: 1px solid #f4c8ca; border-radius: 7px; background: #fff5f5; font-weight: 800; }
.editable-cell[contenteditable="true"] { outline: 0; cursor: text; box-shadow: inset 0 0 0 1px #b7daf7; background: #f8fcff !important; }
.editable-cell[contenteditable="true"]:focus { box-shadow: inset 0 0 0 2px var(--blue-500), 0 0 0 3px rgba(22,137,238,.08); background: #fff !important; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 20px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill.critical { color: var(--red); background: #fff0f1; }
.status-pill.immediate { color: var(--orange); background: #fff2eb; }
.status-pill.periodic { color: var(--blue-600); background: var(--blue-100); }
.status-pill.normal { color: var(--green); background: #e9f8f2; }
.empty { padding: 70px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; margin-bottom: 4px; color: var(--navy-900); }

.cards-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.rule-card, .pending-card {
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  box-shadow: var(--shadow);
}
.rule-number { width: 30px; height: 30px; display: grid; place-items: center; margin-bottom: 15px; color: #fff; border-radius: 8px; background: var(--navy-900); font-size: 12px; font-weight: 800; }
.rule-card p, .pending-card p { margin: 0; color: #3d4e61; font-size: 14px; }
.pending-card { position: relative; padding-left: 52px; background: #fffaf0; border-color: #f2dba6; }
.pending-card::before { content: "!"; position: absolute; left: 18px; top: 18px; width: 22px; height: 22px; display: grid; place-items: center; color: #7f5810; border-radius: 6px; background: #f8cf71; font-weight: 800; }
.card-delete { display: none; margin-top: 14px; color: var(--red); border: 0; background: transparent; font-size: 12px; font-weight: 700; }
.editing .card-delete { display: inline-block; }

.edit-ribbon {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: 18px;
  width: min(900px, calc(100% - 32px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 16px 14px 20px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 13px;
  background: rgba(7,24,45,.96);
  box-shadow: 0 16px 50px rgba(3,14,29,.3);
  backdrop-filter: blur(14px);
}
.edit-ribbon[hidden] { display: none; }
.edit-ribbon > div { display: flex; align-items: center; gap: 10px; }
.edit-ribbon span { color: #b9c9da; font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 80; padding: 12px 16px; color: #fff; border-radius: 8px; background: var(--navy-950); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; font-size: 13px; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1150px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar-context { display: none; }
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar { min-height: 64px; padding: 0 16px; gap: 12px; }
  .brand-copy { display: none; }
  .search { width: auto; flex: 1; }
  .search kbd, .icon-button { display: none; }
  .app-shell { padding: 22px 16px 110px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { width: 100%; justify-content: flex-start; }
  .save-indicator { width: 100%; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; justify-content: flex-start; }
  .filter-chips { justify-content: flex-start; }
  .metric-grid, .cards-grid { grid-template-columns: 1fr; }
  .alert-ladder { grid-template-columns: 1fr 1fr; gap: 8px; }
  .alert-level::before { border-radius: 8px !important; }
  .edit-ribbon { align-items: flex-start; flex-direction: column; }
  .edit-ribbon > div { flex-wrap: wrap; }
  .edit-ribbon span { display: none; }
}
@media print {
  body { background: #fff; }
  .topbar, .heading-actions, .tabs, .toolbar-actions, .edit-ribbon, .toast { display: none !important; }
  .app-shell { max-width: none; padding: 18px; }
  .content { min-height: auto; }
  .table-scroll { max-height: none; overflow: visible; }
  .data-panel, .panel, .metric-card, .rule-card, .pending-card { box-shadow: none; break-inside: avoid; }
}

