:root {
  --bg: #edf1f7;
  --ink: #0f1c2e;
  --muted: #5b6b7f;
  --line: #d5deea;
  --card: #ffffff;
  --accent: #e8a317;
  --accent-ink: #0b1d36;
  --head: #0b1d36;
  --head-2: #153255;
  --ok: #1f7a4d;
  --ok-bg: #e7f6ee;
  --danger: #b42318;
  --danger-bg: #fdeceb;
  --warn: #b54708;
  --warn-bg: #fff4e5;
  --radius: 16px;
  --shadow: 0 12px 32px rgba(11, 29, 54, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --pad: clamp(12px, 3vw, 22px);
}

* { box-sizing: border-box; }
html {
  margin: 0;
  padding: 0;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 480px at -5% -15%, #ffe4a8 0%, transparent 55%),
    radial-gradient(900px 420px at 110% -5%, #cfe0ff 0%, transparent 48%),
    linear-gradient(180deg, #f7f9fc 0%, var(--bg) 40%);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
img, svg, video { max-width: 100%; height: auto; }
a { color: #9a6400; text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 13px; }

/* ——— Top bar ——— */
.topbar {
  background: linear-gradient(135deg, var(--head) 0%, var(--head-2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--pad);
  box-shadow: 0 10px 28px rgba(11, 29, 54, 0.28);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  min-width: 0;
}
.brand-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 11px;
  background: linear-gradient(145deg, #ffc14d, var(--accent));
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.brand strong { font-size: 15px; letter-spacing: .02em; display: block; }
.brand span { display: block; font-size: 11px; color: #9aadc4; font-weight: 500; }

.nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: #fff;
  box-shadow: none;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle span,
.nav-toggle span::before,
.nav-toggle span::after {
  display: block;
  width: 18px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  margin: 0 auto;
  position: relative;
  transition: transform .2s ease, opacity .2s ease;
}
.nav-toggle span::before,
.nav-toggle span::after {
  content: "";
  position: absolute;
  left: 0;
}
.nav-toggle span::before { top: -6px; }
.nav-toggle span::after { top: 6px; }
body.nav-open .nav-toggle span { background: transparent; }
body.nav-open .nav-toggle span::before { top: 0; transform: rotate(45deg); }
body.nav-open .nav-toggle span::after { top: 0; transform: rotate(-45deg); }

.topnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.topnav a {
  color: #d5e2f2;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.topnav a:hover,
.topnav a.active {
  background: rgba(232, 163, 23, 0.2);
  color: #fff;
  text-decoration: none;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.topbar-user .email {
  font-size: 12px;
  color: #9aadc4;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar form { display: inline; margin: 0; }
.topbar .btn,
.topbar button.secondary {
  box-shadow: none;
}

.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 29, 54, 0.45);
  z-index: 35;
}

.wrap {
  width: 100%;
  max-width: 1180px;
  margin: 28px auto 56px;
  padding: 0 var(--pad);
}

.page-header,
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header > div,
.page-head > div { min-width: 0; flex: 1 1 220px; }
.page-header h1,
.page-head h1 {
  margin: 0;
  font-size: clamp(22px, 5vw, 30px);
  letter-spacing: -0.03em;
  font-weight: 750;
  word-break: break-word;
}
.page-header p,
.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 22px);
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 750;
}
.card-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.stat::after {
  content: "";
  position: absolute;
  inset: auto -18% -45% auto;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(232, 163, 23, 0.14);
  pointer-events: none;
}
.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat b {
  display: block;
  margin-top: 8px;
  font-size: clamp(26px, 5vw, 34px);
  letter-spacing: -0.04em;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -2px;
  padding-bottom: 2px;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
  min-width: 560px;
}
table.compact { min-width: 0; }
th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  word-break: break-word;
}
th {
  background: #f4f7fb;
  font-weight: 750;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
th:first-child { border-radius: 12px 0 0 0; }
th:last-child { border-radius: 0 12px 0 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfd; }

label {
  display: block;
  font-size: 13px;
  margin: 10px 0 4px;
  font-weight: 650;
  color: var(--muted);
}
label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
label.inline input { width: auto; max-width: none; }
input, select, textarea {
  width: 100%;
  max-width: 420px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  font: inherit;
  color: var(--ink);
}
.card input,
.card select,
.card textarea,
.filters input,
.filters select,
.filters textarea,
.type-item input,
.type-item select,
.password-box input {
  max-width: none;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(232, 163, 23, 0.35);
  border-color: var(--accent);
}
.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}
.row > * {
  flex: 1 1 160px;
  min-width: 0;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.stack { display: grid; gap: 8px; }
.panel-note {
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: linear-gradient(180deg, #ffb84a, var(--accent));
  color: var(--accent-ink);
  border: 0;
  border-radius: 11px;
  padding: 9px 14px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(232, 163, 23, 0.28);
  min-height: 40px;
}
button:hover, .btn:hover { filter: brightness(0.98); text-decoration: none; }
button.secondary, .btn.secondary {
  background: #1a3354;
  color: #fff;
  box-shadow: none;
}
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}
button.danger, .btn.danger {
  background: var(--danger);
  color: #fff;
  box-shadow: none;
}
button.sm, .btn.sm {
  padding: 7px 11px;
  font-size: 12px;
  min-height: 34px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  background: #eef3f9;
  color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.accent { background: #fff1d0; color: #8a5a00; }

.flash, .error {
  padding: 12px 14px;
  margin-bottom: 16px;
  border-radius: 12px;
  font-weight: 650;
  word-break: break-word;
}
.flash {
  background: var(--ok-bg);
  border: 1px solid #b7d4c0;
  color: var(--ok);
}
.error {
  background: var(--danger-bg);
  border: 1px solid #e0b4b4;
  color: var(--danger);
}

.filters {
  margin-bottom: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.type-grid { display: grid; gap: 12px; }
.type-item {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.4fr);
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
}
.type-item .meta { min-width: 0; }
.type-item .meta strong {
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
  word-break: break-word;
}
.type-item .meta .tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.type-item .actions { min-width: 0; }
.type-item form.inline-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px auto;
  gap: 8px;
  align-items: end;
  width: 100%;
}
.type-item form.inline-edit input,
.type-item form.inline-edit select { max-width: none; width: 100%; }
.type-actions {
  align-items: stretch;
  flex-direction: column;
  width: 100%;
}
.type-delete { width: 100%; }
.type-delete button { width: 100%; }

.password-box {
  flex: 1 1 220px;
  min-width: 0;
  max-width: 320px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}
.password-box input { max-width: none; width: 100%; }

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
}

/* Mobile card tables */
.stack-table thead { display: none; }
.stack-table,
.stack-table tbody,
.stack-table tr,
.stack-table td {
  display: block;
  width: 100%;
  min-width: 0;
}
.stack-table tr {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfcfe;
  margin-bottom: 12px;
  padding: 4px 0;
  overflow: hidden;
}
.stack-table tr:last-child { margin-bottom: 0; }
.stack-table td {
  display: grid;
  grid-template-columns: minmax(88px, 34%) minmax(0, 1fr);
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.stack-table td:last-child { border-bottom: 0; }
.stack-table td::before {
  content: attr(data-label);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding-top: 2px;
}
.stack-table td[data-span="full"] {
  grid-template-columns: 1fr;
}
.stack-table td[data-span="full"]::before { margin-bottom: 6px; }
.stack-table tbody tr:hover td { background: transparent; }

body.public {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--pad);
}
body.public .card,
.login {
  width: min(440px, 100%);
  margin: 0;
  border-radius: 20px;
}
.login h1 { margin-top: 0; }
.login input { max-width: none; }
.login button { width: 100%; margin-top: 8px; padding: 12px; }

/* ——— Breakpoints ——— */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar-user .email { display: none; }
}

@media (max-width: 900px) {
  .card-grid { grid-template-columns: 1fr; }
  .type-item { grid-template-columns: 1fr; }
  .type-item form.inline-edit {
    grid-template-columns: 1fr 1fr;
  }
  .type-item form.inline-edit button {
    grid-column: 1 / -1;
  }

  .nav-toggle { display: inline-grid; place-items: center; }
  .topnav,
  .topbar-user {
    display: none;
  }
  body.nav-open .nav-backdrop { display: block; }
  body.nav-open .topnav,
  body.nav-open .topbar-user {
    display: flex;
  }
  body.nav-open .topbar {
    flex-wrap: wrap;
    align-items: stretch;
  }
  body.nav-open .brand { flex: 1; }
  body.nav-open .topnav {
    order: 3;
    flex: 1 1 100%;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0 4px;
    border-top: 1px solid rgba(255,255,255,.12);
    margin-top: 4px;
  }
  body.nav-open .topnav a {
    width: 100%;
    border-radius: 12px;
    padding: 12px 14px;
  }
  body.nav-open .topbar-user {
    order: 4;
    flex: 1 1 100%;
    justify-content: space-between;
    padding: 8px 0 4px;
    border-top: 1px solid rgba(255,255,255,.08);
  }
  body.nav-open .topbar-user .email {
    display: block;
    max-width: none;
  }
}

@media (max-width: 720px) {
  .wrap { margin: 18px auto 40px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .page-header,
  .page-head { align-items: flex-start; }
  .filters.row > * { flex: 1 1 100%; }
  .filters.row button,
  .filters.row .btn { width: 100%; }
  .password-box { max-width: none; width: 100%; }
  .user-actions > form,
  .user-actions > p { width: 100%; }
  .user-actions button { width: 100%; }
  .actions .btn,
  .actions button { flex: 1 1 auto; }

  /* Stack labeled tables on small phones */
  table.responsive {
    min-width: 0;
  }
  table.responsive thead { display: none; }
  table.responsive,
  table.responsive tbody,
  table.responsive tr,
  table.responsive td {
    display: block;
    width: 100%;
  }
  table.responsive tr {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fbfcfe;
    margin-bottom: 12px;
    padding: 4px 0;
  }
  table.responsive tr:last-child { margin-bottom: 0; }
  table.responsive td {
    display: grid;
    grid-template-columns: minmax(84px, 36%) minmax(0, 1fr);
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
  }
  table.responsive td:last-child { border-bottom: 0; }
  table.responsive td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
  }
  table.responsive td[data-label=""] {
    grid-template-columns: 1fr;
  }
  table.responsive td[data-label=""]::before { display: none; }
  table.responsive td[data-span="full"] {
    grid-template-columns: 1fr;
  }
  table.responsive tbody tr:hover td { background: transparent; }

  .table-wrap { overflow: visible; }

  .type-item form.inline-edit {
    grid-template-columns: 1fr;
  }
  .type-item form.inline-edit button,
  .type-delete button {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .card { border-radius: 14px; }
  button, .btn { width: auto; }
  .login button { width: 100%; }
}

@media (min-width: 901px) {
  body.nav-open .nav-backdrop { display: none; }
}
