:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --text: #16302b;
  --muted: #64736e;
  --primary: #256a58;
  --primary-dark: #174c3f;
  --accent: #d4a72c;
  --border: #d8e2de;
  --success: #1d7a4f;
  --error: #b13a35;
  --shadow: 0 12px 28px rgba(25, 57, 49, .08);
  --radius: 15px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
code, pre, textarea, input[type="text"] { font-family: "Cascadia Code", Consolas, monospace; }

.topbar {
  min-height: 74px;
  padding: 10px clamp(18px, 4vw, 58px);
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 28px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 3px 14px rgba(20,50,42,.05);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.brand.large { justify-content: center; margin-bottom: 22px; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 47px;
  height: 47px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-family: Georgia, serif;
  font-size: 29px;
}
.brand strong { display: block; font-family: Georgia, serif; font-size: 27px; line-height: .95; }
.brand small { display: block; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; font-size: 10px; margin-top: 6px; }

nav { display: flex; gap: 5px; flex: 1; }
nav a, .link-button {
  border: 0;
  background: transparent;
  text-decoration: none;
  color: var(--muted);
  padding: 11px 13px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}
nav a:hover, nav a.active, .link-button:hover { color: var(--primary-dark); background: var(--surface-soft); }
.logout-form { margin: 0; }

.page { width: min(1240px, calc(100% - 32px)); margin: 0 auto; padding: 30px 0 54px; }
.hero { padding: 32px 0; }
.hero.compact { padding: 18px 0 25px; }
.hero h1 { font-family: Georgia, serif; font-size: clamp(32px, 5vw, 52px); margin: 5px 0 10px; line-height: 1.03; }
.hero p { max-width: 800px; color: var(--muted); font-size: 17px; line-height: 1.6; margin: 0; }
.eyebrow { display: inline-block; color: var(--primary); font-weight: 800; font-size: 12px; letter-spacing: .13em; }

.grid { display: grid; gap: 22px; }
.two-columns { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); }
.editor-layout { grid-template-columns: 310px minmax(0, 1fr); align-items: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 3vw, 30px);
  margin-bottom: 22px;
}
.muted-card { background: #fbfcfc; }
.sidebar-card { position: sticky; top: 96px; }
.card h2 { margin: 0 0 18px; font-family: Georgia, serif; font-size: 25px; }
.card h3 { margin-top: 26px; }

label { display: grid; gap: 7px; font-weight: 700; margin-bottom: 18px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #bdcbc6;
  border-radius: 9px;
  padding: 12px 13px;
  background: white;
  color: var(--text);
  font-size: 16px;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(37,106,88,.15); border-color: var(--primary); }
.checkbox-line { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.checkbox-line input { width: auto; }
.bottom-align { align-self: end; padding-bottom: 10px; }
.inline-fields { display: flex; gap: 18px; align-items: start; }
.inline-fields > * { flex: 1; }
.hidden { display: none !important; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 9px;
  padding: 12px 17px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}
.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: var(--surface-soft); color: var(--primary-dark); border: 1px solid #c8d9d2; }
.secondary:hover { background: #e2ece8; }
.danger { background: #f8e6e4; color: #8b2622; border: 1px solid #e8c0bd; }
.small { padding: 9px 12px; font-size: 14px; }
.tiny { padding: 7px 9px; font-size: 12px; }
.full { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }

.section-heading, .result-heading { display: flex; justify-content: space-between; align-items: start; gap: 14px; }
.section-heading h2, .result-heading h2 { margin-bottom: 7px; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 900; letter-spacing: .04em; white-space: nowrap; }
.badge.success { background: #dff4e8; color: var(--success); }
.badge.error { background: #f9dfdd; color: var(--error); }
.badge.neutral { background: #e8eeeb; color: #4e625b; }

.code-block { background: #17231f; color: #dce9e4; border-radius: 11px; padding: 16px; overflow: auto; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.compact-code { font-size: 12px; max-height: 320px; }
.inline-code { display: inline-block; max-width: 620px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

.meta-list { display: grid; gap: 10px; }
.meta-list div { display: grid; grid-template-columns: 105px 1fr; gap: 10px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; font-weight: 700; }
.context-strip { display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 12px 15px; border-radius: 10px; background: var(--surface-soft); margin: 16px 0 22px; }

.segment-list { display: grid; gap: 12px; }
.segment { border: 1px solid var(--border); border-left: 5px solid #aabbb5; padding: 14px 16px; border-radius: 10px; background: #fcfdfd; }
.segment.expression { border-left-color: var(--primary); }
.segment-type { display: inline-block; font-size: 10px; letter-spacing: .11em; font-weight: 900; color: var(--muted); margin-right: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 13px; }
.value-chip { background: var(--surface-soft); border-radius: 8px; padding: 8px 10px; }
.path-list { display: grid; gap: 9px; padding-left: 22px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f0f5f3; color: #536861; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.compact-table th, .compact-table td { padding: 8px 9px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 225px; }

.rule-list { display: grid; gap: 8px; }
.rule-list-item { text-decoration: none; border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; color: var(--text); }
.rule-list-item:hover, .rule-list-item.selected { border-color: var(--primary); background: var(--surface-soft); }
.rule-list-item strong, .rule-list-item small { display: block; }
.rule-list-item small { color: var(--muted); margin-top: 5px; }
.syntax-grid { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(280px, 1.2fr); gap: 10px 18px; align-items: center; }
.syntax-grid code { background: #edf3f0; padding: 9px 11px; border-radius: 8px; }
.note { color: var(--muted); font-size: 13px; }

.alert { border-radius: 9px; padding: 12px 14px; margin-bottom: 16px; }
.alert.error { background: #f9dfdd; color: var(--error); }
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #e7f1ed 0, var(--bg) 52%); }
.auth-card { width: min(460px, 100%); background: white; border: 1px solid var(--border); border-radius: 18px; padding: 32px; box-shadow: var(--shadow); }
.auth-card h1 { font-family: Georgia, serif; text-align: center; font-size: 32px; margin: 5px 0 10px; }
.auth-card p { color: var(--muted); line-height: 1.55; }
.footer { color: var(--muted); text-align: center; padding: 0 18px 28px; font-size: 12px; }

details summary { cursor: pointer; font-weight: 700; color: var(--primary); }

@media (max-width: 900px) {
  .two-columns, .editor-layout { grid-template-columns: 1fr; }
  .sidebar-card { position: static; }
  .topbar { flex-wrap: wrap; gap: 8px 16px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  .logout-form { margin-left: auto; }
}

@media (max-width: 620px) {
  .page { width: min(100% - 20px, 1240px); }
  .inline-fields, .inline-fields.responsive { flex-direction: column; gap: 0; }
  .syntax-grid { grid-template-columns: 1fr; }
  .section-heading, .result-heading { align-items: flex-start; flex-direction: column; }
  .card { padding: 18px; }
  .brand { min-width: auto; }
  .brand strong { font-size: 23px; }
}
