* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: #2e231b;
  background: #f6efe7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body:not(.logged-in) .sidebar,
body:not(.logged-in) .main {
  display: none;
}

body.logged-in .login-view {
  display: none;
}

.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 30px;
  border: 1px solid #eadfd2;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(107, 75, 48, 0.1);
}

.login-panel h1 {
  margin: 8px 0 22px;
  font-size: 26px;
  color: #3f2d24;
}

.login-panel label {
  display: block;
  margin-bottom: 16px;
  color: #5f4b3f;
  font-weight: 700;
}

.login-panel input {
  width: 100%;
  margin-top: 8px;
}

.login-panel button {
  width: 100%;
  margin-top: 6px;
}

.login-brand {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 28px 18px;
  background: #fff8f1;
  color: #fff;
  border-right: 1px solid #eadfd2;
  box-shadow: 8px 0 28px rgba(107, 75, 48, 0.05);
}

.brand {
  display: flex;
  align-items: center;
  min-height: 48px;
  margin-bottom: 30px;
  padding: 0 12px;
  font-size: 19px;
  font-weight: 700;
  color: #8f4f2f;
}

.nav,
button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.nav {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  padding: 13px 14px;
  color: #6f5a4d;
  background: transparent;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav:hover {
  color: #8f4f2f;
  background: #fff1e6;
}

.nav.active {
  color: #fff;
  background: #c97443;
  box-shadow: 0 8px 18px rgba(201, 116, 67, 0.18);
}

.main {
  min-height: 100vh;
  margin-left: 248px;
  padding: 28px 34px 48px;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  margin-bottom: 28px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

input,
select,
textarea {
  border: 1px solid #ead8ca;
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff;
  color: #2e231b;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #d88b61;
  box-shadow: 0 0 0 3px rgba(216, 139, 97, 0.14);
}

input[readonly] {
  color: #8f796b;
  background: #f7efe8;
  cursor: not-allowed;
}

button {
  min-height: 42px;
  padding: 10px 16px;
  color: #fff;
  background: #c97443;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  background: #b96135;
  box-shadow: 0 8px 16px rgba(178, 97, 53, 0.16);
  transform: translateY(-1px);
}

button.danger {
  background: #b33a3a;
}

button.danger:hover {
  background: #963030;
}

button.danger-soft {
  color: #a7382f;
  background: #fff0ed;
  box-shadow: none;
}

button.danger-soft:hover {
  color: #fff;
  background: #b33a3a;
}

button.ghost {
  color: #9a5c3d;
  background: #fff4eb;
  box-shadow: none;
}

button.ghost:hover {
  background: #fee7d5;
  box-shadow: 0 8px 16px rgba(160, 103, 69, 0.12);
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric {
  padding: 20px;
  border: 1px solid #eadfd2;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(107, 75, 48, 0.06);
}

.metric b {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.hint {
  margin: -8px 0 22px;
  padding: 13px 16px;
  border-left: 4px solid #d88b61;
  border-radius: 8px;
  background: #fff6ee;
  color: #866f61;
  line-height: 1.6;
}

.config-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 18px;
  padding: 24px 26px;
  border: 1px solid #eadfd2;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(107, 75, 48, 0.06);
}

.config-header h1 {
  margin: 4px 0 8px;
  color: #3f2d24;
  font-size: 30px;
  line-height: 1.15;
}

.config-header p {
  max-width: 680px;
  margin: 0;
  color: #856f60;
  line-height: 1.7;
}

.page-kicker {
  color: #c97443;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.config-actions {
  display: flex;
  flex-shrink: 0;
  gap: 10px;
}

.config-nav {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  padding: 10px;
  border: 1px solid #eadfd2;
  border-radius: 12px;
  background: rgba(255, 248, 241, 0.96);
  box-shadow: 0 8px 24px rgba(107, 75, 48, 0.05);
}

.config-nav button {
  min-height: 38px;
  padding: 9px 14px;
  border-radius: 999px;
  color: #7b5a48;
  background: #fff;
  border: 1px solid #f0e4d8;
  font-size: 14px;
  font-weight: 700;
  box-shadow: none;
}

.config-nav button:hover,
.config-nav button.active {
  color: #fff;
  background: #c97443;
  border-color: #c97443;
  box-shadow: 0 8px 16px rgba(201, 116, 67, 0.16);
  transform: none;
}

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

.panel {
  padding: 22px;
  border: 1px solid #eadfd2;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(107, 75, 48, 0.055);
  scroll-margin-top: 88px;
}

.panel.wide {
  grid-column: 1 / -1;
}

.config-filtered .config-grid {
  grid-template-columns: 1fr;
}

.config-filtered .panel {
  grid-column: 1 / -1;
}

.panel h2,
.panel-title h2 {
  margin: 0;
  font-size: 18px;
  color: #4d3427;
}

.panel > h2 {
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid #f0e4d8;
}

.panel label {
  display: block;
  margin-bottom: 14px;
  color: #5f4b3f;
  font-size: 14px;
  line-height: 1.4;
}

.panel label:last-child {
  margin-bottom: 0;
}

.panel input,
.panel select,
.panel textarea {
  width: 100%;
  margin-top: 6px;
}

.check {
  display: flex !important;
  gap: 8px;
  align-items: center;
}

.check input {
  width: auto !important;
  margin: 0 !important;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid #f0e4d8;
}

.rule-table {
  overflow: auto;
}

.rule-table table {
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
}

.rule-table input,
.rule-table select {
  min-width: 100px;
  width: 100%;
}

.rule-table th:first-child,
.rule-table td:first-child {
  border-left: 1px solid #f0e4d8;
}

.rule-table th,
.rule-table td {
  border-right: 1px solid #f0e4d8;
}

.rule-table th {
  border-top: 1px solid #f0e4d8;
}

.form-grid {
  display: grid;
  grid-template-columns: 2fr repeat(4, 1fr) 100px 120px 1.6fr 140px;
  gap: 10px;
  margin-bottom: 16px;
}

.table {
  overflow: auto;
  border: 1px solid #eadfd2;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(107, 75, 48, 0.05);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px;
  border-bottom: 1px solid #f0e4d8;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #f6ece2;
  font-weight: 700;
  color: #6d4a35;
}

.muted {
  color: #6b7b83;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(39, 26, 18, 0.45);
}

.modal.show {
  display: flex;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 18px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(84, 52, 28, 0.18);
}

.modal-panel label {
  display: block;
  margin-bottom: 10px;
}

.modal-panel input,
.modal-panel select,
.modal-panel textarea {
  width: 100%;
  margin-top: 6px;
}

.question-title {
  max-width: 360px;
  white-space: normal;
}

.action-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 230px;
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    width: auto;
    padding: 18px;
  }

  .main {
    margin-left: 0;
    padding: 20px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .config-grid {
    grid-template-columns: 1fr;
  }

  .config-header {
    align-items: stretch;
    flex-direction: column;
    padding: 20px;
  }

  .config-actions {
    width: 100%;
  }

  .config-actions button {
    flex: 1;
  }
}
