:root {
  --bg: #f5faff;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #020817;
  --muted: #475569;
  --line: #d7e0ea;
  --accent: #0284c7;
  --accent-dark: #0f3f73;
  --warning: #d97706;
  --danger: #e11d48;
  --success: #059669;
  --info: #0284c7;
  --sidebar: #0f1f33;
  --sidebar-soft: #1b3553;
  --shadow: 0 2px 8px rgba(15, 31, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: var(--sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 26px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 14px 44px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #0ea5e9;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #cbd5e1;
  font-size: 13px;
  margin-top: 3px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #d8e0e7;
  display: flex;
  gap: 10px;
  padding: 13px 20px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--sidebar-soft);
  border-color: transparent;
  color: #ffffff;
}

.nav-item.active {
  border-left: 3px solid #0ea5e9;
  padding-left: 17px;
}

.icon {
  display: inline-grid;
  font-weight: 800;
  height: 22px;
  place-items: center;
  width: 22px;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.main {
  padding: 34px 40px;
  min-width: 0;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 22px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.storage-status {
  color: var(--muted);
  display: inline-block;
  font-size: 13px;
  margin-top: 8px;
}

.storage-status.cloud {
  color: var(--success);
  font-weight: 700;
}

.storage-status.local {
  color: var(--warning);
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
  margin-bottom: 0;
}

h2 {
  font-size: 18px;
  margin-bottom: 0;
}

h3 {
  font-size: 16px;
  margin-bottom: 6px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
}

.primary-button {
  background: #0f3f73;
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: #0b315b;
}

.secondary-button {
  background: #e8f0f7;
  color: #0f3f73;
}

.danger-button {
  background: #fee4e2;
  color: var(--danger);
}

.ghost-button {
  align-items: center;
  background: var(--sidebar-soft);
  color: #ffffff;
  display: flex;
  justify-content: center;
}

.file-button input {
  display: none;
}

.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1.5fr repeat(3, minmax(150px, 1fr));
  margin-bottom: 30px;
  padding: 28px 30px;
}

label span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

input,
select,
textarea {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  min-height: 40px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 30px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 112px;
  padding: 22px 20px;
  position: relative;
}

.metric::before {
  background: #cbd5e1;
  border-radius: 8px 0 0 8px;
  content: "";
  inset: 0 auto 0 0;
  position: absolute;
  width: 4px;
}

.metric:nth-child(2)::before,
.metric:nth-child(3)::before {
  background: var(--success);
}

.metric:nth-child(4)::before,
.metric:nth-child(5)::before {
  background: var(--warning);
}

.metric:nth-child(6)::before {
  background: var(--info);
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 14px;
  text-transform: uppercase;
}

.metric strong {
  font-size: 28px;
}

.content-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px 30px;
}

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

.count-pill,
.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  padding: 7px 9px;
  white-space: nowrap;
}

.count-pill {
  background: var(--surface-2);
  color: var(--muted);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

.badge.warning {
  background: #fef3c7;
  color: var(--warning);
}

.badge.success {
  background: #dcfce7;
  color: var(--success);
}

.badge.info {
  background: #dbeafe;
  color: var(--info);
}

.badge.neutral {
  background: var(--surface-2);
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 10px;
}

.risk-item,
.operator-card,
.reason-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.risk-item {
  display: grid;
  gap: 10px;
}

.risk-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reason-chart {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 8px;
}

.bar-label {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.bar-track {
  background: var(--surface-2);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.bar-fill {
  background: var(--accent);
  height: 100%;
}

.table-panel {
  padding: 0;
}

.table-panel .panel-header {
  padding: 18px 18px 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 920px;
  width: 100%;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

.icon-button {
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  min-width: 40px;
  padding: 0 10px;
}

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

.operator-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, 1fr);
  margin: 14px 0;
}

.operator-stat {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
}

.operator-stat span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 4px;
}

.operator-stat strong {
  font-size: 20px;
}

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

.reason-item {
  display: grid;
  gap: 10px;
}

.reason-item-header {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.reason-actions {
  display: flex;
  gap: 8px;
}

.reason-form-grid {
  grid-template-columns: 140px minmax(0, 1fr);
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 26px 80px rgba(17, 27, 39, 0.28);
  max-width: 980px;
  padding: 0;
  width: calc(100vw - 42px);
}

dialog::backdrop {
  background: rgba(18, 28, 38, 0.45);
}

form {
  padding: 22px;
}

.modal-header,
.modal-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal-header {
  margin-bottom: 18px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

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

.wide {
  display: block;
  margin-top: 12px;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.recurrence-notice {
  border-radius: 8px;
  display: none;
  margin-top: 14px;
  padding: 12px;
}

.recurrence-notice.active {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  display: block;
}

.import-preview {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: none;
  margin-top: 12px;
  max-height: 180px;
  overflow: auto;
  padding: 12px;
}

.import-preview.active {
  display: block;
}

.import-preview strong {
  color: var(--text);
}

.empty {
  color: var(--muted);
  padding: 16px 0;
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-grid,
  .operator-grid {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    min-height: auto;
  }

  .nav,
  .sidebar-footer,
  .topbar,
  .topbar-actions {
    align-items: stretch;
    display: grid;
  }

  .main {
    padding: 18px;
  }

  .metric-grid,
  .filters,
  .form-grid,
  .reason-list {
    grid-template-columns: 1fr;
  }
}
