:root {
  --bg: #f4f7f8;
  --surface: #fff;
  --surface-soft: #f8fafb;
  --text: #172329;
  --muted: #6b7a80;
  --border: #dfe7e9;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e6f4f2;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #087443;
  --success-soft: #ecfdf3;
  --shadow: 0 8px 30px rgba(25, 45, 52, .07);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

button, input { font: inherit; }

a { color: inherit; }

.page-shell {
  width: min(1140px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 60px;
}

.page-header { padding: 34px 0 24px; }

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .14em;
}

h1 {
  margin: 0 0 10px;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.06;
  letter-spacing: -.035em;
}

.subtitle {
  max-width: 900px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.company-switcher {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.company-button {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 2px 10px rgba(25,45,52,.04);
  transition: .18s ease;
}

.company-button:hover { border-color: #b9cccf; transform: translateY(-1px); }
.company-button.active { border-color: var(--accent); background: var(--accent); color: #fff; }

.rules-panel,
.forbidden-panel {
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0 0 5px;
  font-size: 22px;
  letter-spacing: -.02em;
}

.section-heading p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.rules-count {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.rules-list { display: grid; gap: 9px; }

.rule-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 13px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
}

.rule-number {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.rule-content h3 { margin: 2px 0 7px; font-size: 15px; line-height: 1.4; }
.rule-description { margin: 0 0 11px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.rule-atc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rule-atc {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 11px;
  background: #fff;
  border: 1px solid var(--border);
}
.rule-atc span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.rule-atc strong { display: block; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.rule-atc.forbidden { border-color: #f0d0cc; background: var(--danger-soft); }
.rule-atc.forbidden strong { color: var(--danger); }
.rule-atc.allowed { border-color: #c9e9d7; background: var(--success-soft); }
.rule-atc.allowed strong { color: var(--success); }

.forbidden-panel { margin-top: 22px; }

.insurance-search {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  min-height: 58px;
  margin: 0 -2px 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.insurance-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(15,118,110,.10), var(--shadow); }
.search-icon { width: 48px; flex: 0 0 48px; text-align: center; color: var(--muted); font-size: 26px; transform: rotate(-20deg); }
.insurance-search input { min-width: 0; flex: 1; height: 56px; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 15px; }
.insurance-search input::placeholder { color: #8a979b; }
.insurance-search button { height: 42px; margin-right: 8px; padding: 0 16px; border: 0; border-radius: 11px; background: var(--accent); color: #fff; font-weight: 800; cursor: pointer; }
.insurance-search button:hover { background: var(--accent-dark); }
.clear-search { width: 34px; height: 34px; display: grid; place-items: center; margin-right: 4px; border-radius: 9px; background: var(--surface-soft); color: var(--muted); text-decoration: none; font-size: 22px; }

.atc-tree { display: grid; gap: 5px; }
.atc-node { border: 1px solid transparent; border-radius: 12px; }
.atc-node[open] { background: var(--surface-soft); border-color: var(--border); }
.atc-node summary { display: flex; align-items: center; gap: 8px; min-height: 43px; padding: 7px 10px; cursor: pointer; list-style: none; border-radius: 11px; }
.atc-node summary::-webkit-details-marker { display: none; }
.atc-node summary:hover { background: #f1f6f6; }
.atc-chevron { width: 19px; color: var(--muted); font-size: 23px; line-height: 1; transition: transform .15s ease; }
.atc-node[open] > summary .atc-chevron { transform: rotate(90deg); }
.atc-code { flex: 0 0 auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; font-weight: 900; color: var(--accent-dark); }
.forbidden-code { color: var(--danger); }
.atc-name { min-width: 0; font-size: 14px; line-height: 1.45; }
.atc-badge { flex: 0 0 auto; margin-left: auto; padding: 4px 7px; border-radius: 7px; background: var(--danger-soft); color: var(--danger); font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; }
.medicine-count { flex: 0 0 auto; min-width: 23px; padding: 3px 6px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-dark); text-align: center; font-size: 10px; font-weight: 900; }
.atc-node-body { padding: 0 8px 8px 28px; }
.atc-node-body > .atc-node { margin-top: 3px; }

.medicine-row { display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 6px 9px; border-top: 1px solid var(--border); }
.medicine-mark { color: var(--danger); font-size: 18px; line-height: 1; }
.medicine-name { min-width: 0; flex: 1; font-size: 13px; line-height: 1.4; }
.medicine-atc { flex: 0 0 auto; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); font-size: 11px; }

.empty-state { padding: 55px 20px 40px; text-align: center; }
.empty-icon { color: var(--accent); font-size: 40px; transform: rotate(-20deg); }
.empty-state h3 { margin: 10px 0 5px; font-size: 20px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }

@media (max-width: 700px) {
  .page-shell { width: min(100% - 20px, 1100px); }
  .rules-panel, .forbidden-panel { padding: 15px; border-radius: 15px; }
  .section-heading { flex-direction: column; gap: 8px; }
  .rule-atc-grid { grid-template-columns: 1fr; }
  .insurance-search button { display: none; }
  .medicine-atc { display: none; }
  .atc-name { font-size: 13px; }
}
