:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #667387;
  --line: #dce3ea;
  --primary: #176b87;
  --primary-dark: #0f4f64;
  --accent: #25a36f;
  --warn: #c94b3b;
  --soft: #eaf6f5;
  --shadow: 0 18px 42px rgba(24, 33, 47, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #eaf3f4 0, #f3f6f8 310px), var(--bg);
}

button, input, select { font: inherit; }

.topbar {
  min-height: 96px;
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  color: #fff;
  background: linear-gradient(135deg, #12313d, #176b87);
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 800;
}

.eyebrow {
  margin: 0;
  opacity: .74;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.top-actions, .filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

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

.sidebar {
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(10px);
}

.tab {
  width: 100%;
  min-height: 46px;
  margin-bottom: 8px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-weight: 700;
}

.tab.active, .tab:hover {
  border-color: #b9d8da;
  background: var(--soft);
  color: var(--primary-dark);
}

.content {
  min-width: 0;
  padding: 28px;
}

.panel {
  display: none;
  max-width: 1320px;
  margin: 0 auto;
}

.panel.active { display: block; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.section-head .eyebrow { color: var(--muted); }

h2, h3 { margin: 0; }
h2 { font-size: 28px; letter-spacing: 0; }
h3 { margin-bottom: 12px; font-size: 17px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid rgba(220, 227, 234, .85);
  border-radius: 8px;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(23, 107, 135, .13);
}

.search { max-width: 300px; }

button {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 800;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

button:hover { transform: translateY(-1px); }

.primary {
  color: #fff;
  background: var(--primary);
}

.primary:hover { background: var(--primary-dark); }

.ghost {
  border-color: var(--line);
  color: var(--ink);
  background: #fff;
}

.ghost:hover {
  border-color: #b9d8da;
  background: #f8fbfc;
}

.danger {
  color: #fff;
  background: var(--warn);
}

.table-wrap {
  overflow: auto;
  border: 1px solid rgba(220, 227, 234, .9);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 720px;
}

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

th {
  color: var(--muted);
  background: #f8fafb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

tbody tr:hover { background: #f9fcfc; }
tbody tr:last-child td { border-bottom: 0; }

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border: 1px solid rgba(220, 227, 234, .85);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric::after {
  content: "";
  position: absolute;
  right: -26px;
  top: -26px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: rgba(37, 163, 111, .12);
}

.metric span {
  display: block;
  font-size: 36px;
  font-weight: 800;
  color: var(--primary-dark);
}

.metric small {
  color: var(--muted);
  font-weight: 700;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr);
  gap: 18px;
}

.stats-list {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(24, 33, 47, .06);
}

.stat-row strong {
  color: var(--primary-dark);
}

.phone-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #0d6b45;
  background: #e7f7ef;
  font-weight: 800;
  text-decoration: none;
}

.phone-link:hover {
  color: #fff;
  background: var(--accent);
}

.notice {
  min-height: 20px;
  margin: -4px 0 12px;
  color: var(--warn);
  font-weight: 700;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #18212f;
  opacity: 0;
  transform: translateY(10px);
  transition: .2s ease;
  pointer-events: none;
  box-shadow: var(--shadow);
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tab {
    width: auto;
    min-width: 120px;
    text-align: center;
  }

  .content { padding: 16px; }
  .section-head { align-items: stretch; flex-direction: column; }
  .search { max-width: none; }
  .form-grid, .split { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}

@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
  .top-actions, .filters { width: 100%; }
  .top-actions button, .filters input, .filters select { flex: 1; min-width: 140px; }
}

@media print {
  body { background: #fff; }
  .topbar, .sidebar, .form-grid, .filters, .search, .no-print, #toast, .notice { display: none !important; }
  .app-shell, .content, .panel { display: block; padding: 0; min-height: 0; }
  .panel { display: none; }
  #escalas { display: block; }
  .table-wrap { border: 0; overflow: visible; box-shadow: none; }
  table { min-width: 0; }
}
