:root {
  --brand-primary: #111;
  --brand-accent: #E53935;
  --brand-bg: #f6f7f8;
  --brand-text: #1a1a1a;
  --brand-muted: #6b7280;
  --sidebar-bg: #111;
  --sidebar-text: #e5e5e5;
  --sidebar-hover: #222;
  --card-bg: #fff;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --success-bg: #dcfce7;
  --success-text: #166534;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--brand-text);
  background: var(--brand-bg);
  line-height: 1.5;
}

body.public, .public body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  transform: translateX(0);
  transition: transform 0.2s ease;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid #333;
}

.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--brand-accent);
  color: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.brand-name {
  font-weight: 600;
  font-size: 1.125rem;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 1.5rem;
  cursor: pointer;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.nav-link:hover, .nav-link.is-active {
  background: var(--sidebar-hover);
}

.nav-icon {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #333;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.user-name {
  font-weight: 500;
  font-size: 0.875rem;
}

.logout-button {
  background: transparent;
  border: 1px solid #444;
  color: var(--sidebar-text);
  padding: 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}

.logout-button:hover {
  background: #222;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

.main {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main.public {
  margin-left: 0;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.locale-switcher a {
  color: var(--brand-muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
}

.locale-switcher a.is-active {
  color: var(--brand-primary);
  font-weight: 600;
  border-bottom: 2px solid var(--brand-accent);
}

.content {
  padding: 1.5rem;
  flex: 1;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-header h2, .card-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.widget {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  text-align: center;
  border-left: 4px solid transparent;
}

.widget-value {
  font-size: 1.75rem;
  font-weight: 700;
}

.widget-label {
  color: var(--brand-muted);
  font-size: 0.875rem;
}

.widget-warning { border-left-color: #f59e0b; }
.widget-danger { border-left-color: var(--brand-accent); }

.grid.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.span-2 { grid-column: span 2; }

/* Tables */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table th, .table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.table th {
  background: #f9fafb;
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--brand-text);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
}

.button.is-primary {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.button.is-danger {
  background: var(--brand-accent);
  color: #fff;
  border-color: var(--brand-accent);
}

.button.is-small {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

.button.is-full {
  width: 100%;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--brand-accent);
  outline-offset: 0;
}

.actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.inline-form { display: inline; }

/* Auth */
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.auth-card h1 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.auth-footer {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.875rem;
}

.auth-footer a {
  color: var(--brand-muted);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  background: #f3f4f6;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-low { background: #dcfce7; color: #166534; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-normal { background: #f3f4f6; color: #374151; }

/* Lists */
.list, .priority-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li, .priority-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.list li:last-child, .priority-list li:last-child {
  border-bottom: none;
}

.list a, .priority-list a {
  color: var(--brand-text);
  text-decoration: none;
  display: block;
}

.list a:hover, .priority-list a:hover {
  color: var(--brand-accent);
}

.priority-high { border-left: 3px solid var(--brand-accent); padding-left: 0.75rem; }
.priority-medium { border-left: 3px solid #f59e0b; padding-left: 0.75rem; }
.priority .reason {
  display: block;
  color: var(--brand-muted);
  font-size: 0.875rem;
}

.empty {
  color: var(--brand-muted);
  font-size: 0.875rem;
  padding: 1rem 0;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.search-form input,
.search-form select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Flash */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.flash-error {
  background: var(--error-bg);
  color: var(--error-text);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border);
  margin: 1rem 0;
  overflow-x: auto;
}

.tab {
  padding: 0.625rem 1rem;
  color: var(--brand-muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 0.875rem;
}

.tab.is-active, .tab:hover {
  color: var(--brand-text);
  border-bottom-color: var(--brand-accent);
}

.page-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.client-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.client-header h2 {
  margin: 0;
}

.badges {
  display: flex;
  gap: 0.5rem;
}

.definition-list {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 2fr;
  gap: 0.5rem 1rem;
}

.definition-list dt {
  color: var(--brand-muted);
  font-size: 0.875rem;
}

.definition-list dd {
  margin: 0;
  font-weight: 500;
}

/* Forms */
.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.form-section legend {
  font-weight: 600;
  padding: 0 0.5rem;
}

.choice-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.375rem 0;
  font-weight: normal;
}

.hint {
  display: block;
  color: var(--brand-muted);
  font-size: 0.75rem;
}

/* Anamnesis builder */
.section-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.section-block h4 {
  margin: 0 0 0.75rem;
}

.field-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.field-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.field-inline {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.field-inline input,
.field-inline select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Onboarding */
.onboarding-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.onboarding-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--brand-muted);
}

.onboarding-step.is-done {
  color: var(--brand-text);
}

.step-marker {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--border);
  font-size: 0.875rem;
}

.onboarding-step.is-done .step-marker {
  background: #dcfce7;
  color: #166534;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-close, .overlay.is-visible, .menu-toggle {
    display: block;
  }

  .main {
    margin-left: 0;
  }

  .form-grid, .grid.two-col, .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .toolbar, .page-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-form {
    flex-direction: column;
  }
}
