:root {
  --ink: #162033;
  --text: #263244;
  --muted: #697386;
  --line: #d9dee8;
  --soft-line: #e8ecf3;
  --surface: #ffffff;
  --surface-soft: #f7f8fb;
  --page: #edf1f6;
  --brand: #173b57;
  --brand-strong: #102a3f;
  --accent: #b88a2a;
  --accent-soft: #f5ead4;
  --danger: #b4232f;
  --danger-soft: #fff1f2;
  --success: #177245;
  --success-soft: #eefaf3;
  --shadow: 0 16px 42px rgba(22, 32, 51, .08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-width: 320px;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(23, 59, 87, .08), rgba(237, 241, 246, 0) 260px),
    var(--page);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(184, 138, 42, .24), transparent 320px),
    linear-gradient(145deg, var(--brand-strong), var(--brand));
}

.login-box {
  width: min(100%, 390px);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 12px;
  padding: 34px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
}

.login-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.login-box h1 {
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 750;
}

.login-box p {
  margin: 6px 0 24px;
  color: var(--muted);
  font-size: .92rem;
}

.login-box input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
}

.login-box input:focus,
.toolbar input:focus,
.toolbar select:focus {
  outline: 3px solid rgba(23, 59, 87, .12);
  border-color: var(--brand);
  background: #fff;
}

.login-box button {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 750;
}

.login-box button:hover {
  background: var(--brand-strong);
}

.login-err {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: .88rem;
}

/* Header */
.panel-header {
  min-height: 74px;
  padding: 14px clamp(16px, 4vw, 36px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--brand-strong);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand-kicker {
  display: block;
  margin-bottom: 2px;
  color: rgba(255, 255, 255, .68);
  font-size: .76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.panel-header h1 {
  font-size: clamp(1.08rem, 2.2vw, 1.42rem);
  font-weight: 750;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  color: rgba(255, 255, 255, .74);
  font-size: .9rem;
  white-space: nowrap;
}

.live-time {
  color: #f1d79d;
  font-variant-numeric: tabular-nums;
}

.header-actions a {
  color: #fff;
  text-decoration: none;
  font-weight: 650;
}

.header-actions a:hover {
  color: #f1d79d;
}

/* Top capacity */
.capacity-top {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 12px clamp(16px, 4vw, 36px);
  background: rgba(255, 255, 255, .95);
  border-bottom: 1px solid var(--soft-line);
  backdrop-filter: blur(14px);
}

.capacity-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(160px, 230px) 1fr;
  align-items: center;
  gap: 18px;
}

.cap-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.cap-copy span {
  color: var(--muted);
  font-size: .86rem;
  font-weight: 650;
}

.cap-copy strong {
  color: var(--ink);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cap-bar-wrap {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #dde4ef;
}

.cap-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .45s ease;
}

/* Dashboard */
.panel-body {
  width: min(100%, 1288px);
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 36px) 42px;
}

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

.stat-card,
.toolbar,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
}

.stat-card .val {
  color: var(--ink);
  font-size: clamp(1.55rem, 3vw, 2.2rem);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-card .lbl {
  margin-top: 8px;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 600;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 160px 150px auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
}

.toolbar input,
.toolbar select {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.toggle-deleted,
.btn-refresh,
.btn-del,
.btn-restore {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
  white-space: nowrap;
}

.toggle-deleted:hover,
.btn-refresh:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.toggle-deleted.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

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

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: .9rem;
}

thead tr {
  background: #f8fafc;
}

th {
  padding: 13px 14px;
  color: #566174;
  text-align: left;
  font-size: .76rem;
  font-weight: 800;
  text-transform: uppercase;
  border-bottom: 1px solid var(--soft-line);
}

td {
  padding: 13px 14px;
  vertical-align: middle;
  border-bottom: 1px solid var(--soft-line);
  color: var(--text);
}

tbody tr:hover {
  background: #fbfcfe;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.deleted-row {
  background: #fff8f8;
  opacity: .72;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge-personal { background: #eaf2ff; color: #1556a7; }
.badge-family { background: var(--accent-soft); color: #78530e; }
.badge-father { background: #e7edf5; color: var(--brand); }
.badge-mother { background: #fde8f1; color: #9a1b55; }
.badge-child { background: #e9f8ee; color: #17633d; }

.code,
.code-deleted {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: .88rem;
  font-weight: 800;
}

.code {
  color: var(--brand);
}

.code-deleted {
  color: #99a1af;
  text-decoration: line-through;
}

.id-cell,
.date-cell,
.muted-cell,
.email-cell {
  color: var(--muted);
  font-size: .84rem;
}

.btn-del,
.btn-restore {
  min-height: 34px;
  padding: 0 11px;
  font-size: .82rem;
}

.btn-del {
  border-color: #fecdd3;
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-del:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-restore {
  border-color: #bfe8cd;
  background: var(--success-soft);
  color: var(--success);
}

.btn-restore:hover {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

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

.error-state {
  color: var(--danger);
}

@media (max-width: 980px) {
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .toolbar input {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  body {
    font-size: 14px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .capacity-inner {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stats-row,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 16px;
  }

  .table-wrap {
    margin-left: -16px;
    margin-right: -16px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  th,
  td {
    padding: 11px 12px;
  }
}
