:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f8f5f;
  --primary-dark: #087044;
  --danger: #b42318;
  --warning: #f97316;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; font-weight: 650; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px 28px;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark, .auth-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}
.brand small { display: block; color: var(--muted); }
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; }
.inline-form { display: inline; margin: 0; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  padding: 0;
}
.link-button.danger { color: var(--danger); }

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 60px;
}
.container.narrow { width: min(760px, calc(100% - 32px)); }
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); line-height: 1.1; margin-bottom: 8px; }
h2 { font-size: 20px; }
.page-heading p, .auth-card p { color: var(--muted); margin-bottom: 0; }

.panel, .stat-card, .auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 22px; margin-bottom: 22px; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card { padding: 22px; }
.stat-card span { display: block; color: var(--muted); margin-bottom: 12px; }
.stat-card strong { font-size: 36px; }
.two-column {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 22px;
}
.two-column.wide-left { grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.6fr); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 13px 10px;
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.empty { color: var(--muted); text-align: center; padding: 28px; }
.actions { display: flex; gap: 10px; align-items: center; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #e8f7ef;
  color: var(--primary-dark);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.badge.urgent { background: #fff2e5; color: var(--warning); }

.button {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-dark); text-decoration: none; }
.button.secondary { background: #e8f7ef; color: var(--primary-dark); }
.button.full { width: 100%; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: white;
  color: var(--text);
  font: inherit;
  margin-top: 6px;
}
textarea { resize: vertical; }
label { font-weight: 700; color: #25324a; }
label small { display: block; color: var(--muted); font-weight: 500; margin-top: 6px; }

.help-text {
  color: var(--muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
}
.help-text code {
  display: inline;
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
}
input:disabled {
  background: #f8fafc;
  color: var(--muted);
}
.form-stack { display: grid; gap: 15px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.span-2 { grid-column: span 2; }
.checkbox { display: flex; align-items: center; gap: 10px; }
.checkbox input { width: auto; margin: 0; }
.filters { display: grid; grid-template-columns: 1fr 220px auto; gap: 12px; margin-bottom: 18px; }
.top-gap { margin-top: 18px; }

.auth-page {
  min-height: calc(100vh - 50px);
  display: grid;
  place-items: center;
  padding: 28px;
}
.auth-card { width: min(420px, 100%); padding: 34px; }
.auth-icon { margin-bottom: 18px; }

.flash {
  padding: 13px 15px;
  border-radius: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  background: white;
}
.flash.success { border-color: #b7e4c7; background: #effaf3; color: #0f5132; }
.flash.error { border-color: #fecaca; background: #fff1f2; color: #991b1b; }

.details-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 9px 12px;
}
.details-list dt { color: var(--muted); font-weight: 750; }
.details-list dd { margin: 0; }
.chat-log { display: grid; gap: 12px; max-height: 680px; overflow-y: auto; padding-right: 4px; }
.chat-bubble {
  border-radius: 15px;
  padding: 12px 14px;
  max-width: 92%;
  border: 1px solid var(--border);
}
.chat-bubble.in { background: #f8fafc; justify-self: start; }
.chat-bubble.out { background: #e8f7ef; justify-self: end; }
.chat-bubble small { color: var(--muted); }
.chat-bubble p { margin: 6px 0 0; white-space: pre-wrap; }
.chat-bubble em { color: var(--danger); display: block; margin-top: 6px; }

.events-list { display: grid; gap: 10px; }
.event-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 4px;
}
.event-row.error { border-color: #fecaca; background: #fff1f2; }
.event-row.warning { border-color: #fed7aa; background: #fff7ed; }
.event-row small { color: var(--muted); }
pre, code {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  display: block;
  overflow-x: auto;
  white-space: pre-wrap;
}
.menu-preview { min-height: 260px; }
.error-box { text-align: left; }
.centered { text-align: center; }
.footer {
  text-align: center;
  padding: 28px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar, .page-heading { align-items: flex-start; flex-direction: column; }
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column, .two-column.wide-left { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .cards-grid, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .nav-links { gap: 10px; font-size: 14px; }
  .panel { padding: 16px; }
  th, td { padding: 10px 8px; }
  .details-list { grid-template-columns: 1fr; }
}
