:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --ink: #1e2522;
  --muted: #68716d;
  --line: #d8d2c4;
  --green: #176f5b;
  --green-dark: #0e4f42;
  --amber: #a35f00;
  --red: #b23a3a;
  --blue: #235789;
  --shadow: 0 18px 40px rgba(42, 38, 30, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #ebe5d9;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #f9f5ea;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 14px;
  letter-spacing: 0;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 34px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #3f4743;
  font-weight: 700;
}

.nav-link:hover,
.nav-link.active {
  background: var(--panel);
  box-shadow: inset 0 0 0 1px rgba(30, 37, 34, 0.08);
}

.sidebar-footer {
  display: grid;
  gap: 14px;
  margin-top: auto;
}

.identity {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
}

.identity strong,
.identity span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity span {
  color: var(--muted);
  font-size: 13px;
}

.main {
  width: min(1180px, 100%);
  min-width: 0;
  padding: 28px;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  align-items: center;
  gap: 40px;
  min-height: calc(100vh - 56px);
}

.auth-copy {
  max-width: 680px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 10px;
  font-size: clamp(32px, 4vw, 60px);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.security-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
}

.security-strip span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.68);
  color: #2f3733;
  font-weight: 800;
}

.auth-card,
.panel,
.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card {
  display: grid;
  gap: 16px;
  padding: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: #39423e;
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #c7c0b2;
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 111, 91, 0.15);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #bbb2a2;
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  text-align: center;
}

.button:hover {
  border-color: #8f8676;
}

.button.primary {
  border-color: var(--green);
  background: var(--green);
  color: #fffefa;
}

.button.primary:hover {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.button.ghost {
  background: transparent;
}

.button.danger {
  border-color: rgba(178, 58, 58, 0.35);
  color: var(--red);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.button.full {
  width: 100%;
}

.text-link {
  color: var(--green-dark);
  font-weight: 800;
}

.form-note {
  margin: 0;
  font-size: 12px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.page-header h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 54px);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card {
  min-height: 112px;
  padding: 18px;
}

.metric-card span {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 26px;
  line-height: 1.1;
}

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

.config-layout {
  grid-template-columns: 360px minmax(0, 1fr);
}

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-title h2 {
  font-size: 19px;
}

.panel form,
form.panel {
  display: grid;
  gap: 14px;
}

.rule-list {
  display: grid;
  gap: 10px;
}

.rule-list span {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f4ea;
  font-weight: 800;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #ece7dc;
  color: #4c544f;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-green {
  background: rgba(23, 111, 91, 0.12);
  color: var(--green-dark);
}

.badge-amber {
  background: rgba(163, 95, 0, 0.12);
  color: var(--amber);
}

.badge-red {
  background: rgba(178, 58, 58, 0.12);
  color: var(--red);
}

.table-panel {
  margin-bottom: 18px;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td code,
dd code {
  padding: 2px 5px;
  border-radius: 6px;
  background: #eee9dd;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.table-actions form {
  display: inline-flex;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  border: 1px dashed #bfb7a8;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.detail-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.qr-panel {
  display: grid;
  align-content: start;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  width: min(100%, 288px);
  aspect-ratio: 1;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  gap: 2px;
}

.qr-grid span {
  border-radius: 1px;
  background: transparent;
}

.qr-grid span.filled {
  background: var(--ink);
}

.config-block {
  max-height: 420px;
  margin: 0;
  overflow: auto;
  padding: 16px;
  border-radius: 8px;
  background: #161b19;
  color: #f9f5ea;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 800;
}

.flash.success {
  background: rgba(23, 111, 91, 0.12);
  color: var(--green-dark);
}

.flash.error {
  background: rgba(178, 58, 58, 0.12);
  color: var(--red);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 16px;
  }

  .sidebar-footer {
    margin-top: 16px;
  }

  .main {
    padding: 18px;
  }

  .auth-panel,
  .split-layout,
  .config-layout {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
  }

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

  .auth-card,
  .panel,
  .metric-card {
    box-shadow: none;
  }

  .detail-list div {
    grid-template-columns: 1fr;
  }
}
