:root {
  --bg: #f4f1eb;
  --surface: #ffffff;
  --surface-2: #faf6ef;
  --ink: #1d1b18;
  --muted: #6c665d;
  --line: #e4dbcf;
  --primary: #7d3728;
  --primary-2: #a45a35;
  --accent: #b68a2a;
  --success: #207561;
  --danger: #b93a3a;
  --shadow: 0 16px 36px rgba(31, 24, 18, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(125, 55, 40, 0.08), transparent 28%),
    linear-gradient(180deg, #f7f3ec 0%, #f2efe8 100%);
}

button, input { font: inherit; }

#app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: linear-gradient(180deg, #fff 0%, #fbf7f1 100%);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: white;
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  box-shadow: var(--shadow);
}

.brand-name { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 0.84rem; margin-top: 2px; }

.nav { display: grid; gap: 6px; }
.nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover, .nav-item.active {
  background: rgba(125, 55, 40, 0.08);
  border-color: rgba(125, 55, 40, 0.14);
}

.main { padding: 24px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 18px;
}

h1 { margin: 0; font-size: 2rem; line-height: 1.1; }
#page-subtitle { margin: 6px 0 0; color: var(--muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input {
  min-width: 250px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  cursor: pointer;
}
.btn.ghost {
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--line);
}
.btn.primary {
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  color: white;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.metric .label { color: var(--muted); font-size: 0.84rem; }
.metric .value { font-size: 1.8rem; font-weight: 800; margin-top: 6px; }
.metric .meta { color: var(--muted); font-size: 0.84rem; margin-top: 4px; }

.panel {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-body { padding: 0; }

.filters {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(140px, 1fr));
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
.filters input, .filters select {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid #eee7dc;
  font-size: 0.92rem;
  vertical-align: top;
}
th {
  position: sticky;
  top: 0;
  background: #f7f2ea;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  background: #efe8dc;
  color: #574f45;
  font-size: 0.78rem;
  white-space: nowrap;
}
.badge.in { background: rgba(32, 117, 97, 0.12); color: var(--success); }
.badge.out { background: rgba(185, 58, 58, 0.12); color: var(--danger); }

.empty {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  #app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main { padding: 16px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .toolbar input { min-width: 0; width: 100%; }
  .summary-grid { grid-template-columns: 1fr; }
}

.login-dialog {
  width: min(420px, calc(100vw - 24px));
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 30px 90px rgba(32, 24, 18, 0.28);
}
.login-dialog::backdrop { background: rgba(28, 22, 18, 0.52); }
.login-card {
  padding: 22px;
  display: grid;
  gap: 12px;
  background: #fff;
}
.login-card h2 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 0.86rem; }
.login-card input {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.login-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
.login-error { color: var(--danger); min-height: 1.2em; font-size: 0.88rem; }
.login-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
}
.login-divider::before,
.login-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.record-dialog {
  width: min(720px, calc(100vw - 24px));
  border: 0;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 30px 90px rgba(32, 24, 18, 0.28);
}
.record-dialog::backdrop { background: rgba(28, 22, 18, 0.52); }
.record-card {
  padding: 18px;
  display: grid;
  gap: 14px;
  background: white;
}
.record-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.record-head h2 { margin: 0; }
.record-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.record-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 0.86rem; }
.record-fields input,
.record-fields select,
.record-fields textarea {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
  font: inherit;
}
.record-fields .full { grid-column: 1 / -1; }
.record-actions { display: flex; justify-content: space-between; gap: 10px; }
.btn.danger { background: var(--danger); color: white; }
