:root {
  --navy-900: #141f33;
  --navy-800: #1b2942;
  --navy-700: #24354f;
  --navy-600: #2f4260;
  --slate-header: #3e5871;
  --bg: #eef1f5;
  --panel: #ffffff;
  --border: #dde3ea;
  --text: #1f2937;
  --muted: #6b7280;
  --teal: #12a596;
  --teal-dark: #0e8578;
  --teal-bg: #e3f7f4;
  --red: #e5534b;
  --red-dark: #c73a32;
  --red-bg: #fdeceb;
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }

/* ---------- layout ---------- */

.topbar {
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--teal-dark);
}
.topbar .brand .icon { width: 24px; height: 24px; }

.topbar .menu-toggle {
  background: none; border: none; color: var(--navy-800); cursor: pointer; padding: 6px; display: none;
}

.topbar .user-area { display: flex; align-items: center; gap: 12px; }
.topbar .user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--bg);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.topbar .user-info { line-height: 1.3; text-align: right; }
.topbar .user-info .name { font-weight: 600; font-size: 13px; }
.topbar .user-info .email { font-size: 11.5px; color: var(--muted); }
.topbar .logout-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--red-bg); color: var(--red);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.topbar .logout-btn:hover { background: var(--red); color: white; }

.app-body { display: flex; align-items: flex-start; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--navy-900);
  color: #cbd5e1;
  min-height: calc(100vh - 60px);
  padding: 14px 0;
  overflow-y: auto;
}

.sidebar a.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: #d7dee8; font-size: 13.5px;
}
.sidebar a.nav-link:hover { background: var(--navy-700); text-decoration: none; }
.sidebar a.nav-link.active { background: var(--teal); color: white; }

.sidebar details { border-bottom: 1px solid rgba(255,255,255,0.06); }
.sidebar summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #aeb9c9;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.sidebar summary::-webkit-details-marker { display: none; }
.sidebar summary:hover { color: white; }
.sidebar summary .chev { margin-left: auto; transition: transform .15s; }
.sidebar details[open] summary .chev { transform: rotate(180deg); }
.sidebar details[open] summary { color: white; }
.sidebar .group-items a.nav-link { padding-left: 46px; font-size: 13px; }

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px;
}

.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb .sep { margin: 0 6px; }
.breadcrumb .current { color: var(--text); }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { margin: 0 0 4px; font-size: 22px; }
.page-head .subtitle { color: var(--muted); font-size: 13px; margin: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: white; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: white; }
.btn.danger:hover { background: var(--red-dark); }
.btn.outline { background: white; }
.btn.small { padding: 5px 12px; font-size: 12px; border-radius: 16px; }
.btn.icon-only { padding: 6px; border-radius: 50%; }

.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: center; }
.row-actions .btn.edit { background: var(--teal); border-color: var(--teal); color: white; }
.row-actions .btn.edit:hover { background: var(--teal-dark); }
.row-actions .btn.delete { background: var(--red); border-color: var(--red); color: white; }
.row-actions .btn.delete:hover { background: var(--red-dark); }
.row-actions .btn.ghost { background: white; color: var(--navy-700); }

/* ---------- table ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table.data { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.data thead th {
  background: var(--slate-header);
  color: white;
  font-weight: 600;
  text-align: center;
  padding: 12px 10px;
  white-space: nowrap;
}
table.data thead th a { color: white; }
table.data thead th a:hover { text-decoration: none; opacity: .85; }

table.data .filter-row td { background: #f7f9fb; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.data .filter-row input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 12.5px;
}

table.data tbody td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: center;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.data tbody tr:nth-child(even) { background: #f7fafc; }
table.data tbody tr:hover { background: #eef6f5; }

.pw-cell { display: inline-flex; align-items: center; gap: 6px; }
.pw-cell .reveal-btn { font-size: 11px; padding: 3px 9px; }

/* ---------- pagination ---------- */

.pagination { display: flex; gap: 6px; margin-top: 16px; align-items: center; justify-content: center; flex-wrap: wrap; }
.pagination a {
  min-width: 34px; height: 34px; padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: white; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.pagination a:hover { background: #f1f5f9; text-decoration: none; }
.pagination a.active { background: var(--navy-800); border-color: var(--navy-800); color: white; }

/* ---------- forms ---------- */

form.record-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 24px; }
form.record-form .field { display: flex; flex-direction: column; gap: 4px; }
form.record-form .field.wide { grid-column: 1 / -1; }
form.record-form label { font-weight: 600; font-size: 12.5px; color: var(--muted); }
form.record-form input, form.record-form textarea, form.record-form select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit;
}
form.record-form input:focus, form.record-form textarea:focus, form.record-form select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-bg);
}
form.record-form textarea { min-height: 70px; resize: vertical; }
form.record-form .pw-wrap { position: relative; display: flex; gap: 6px; }
form.record-form .pw-wrap input { flex: 1; }

.form-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 8px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; background: var(--teal-bg); color: var(--teal-dark); font-weight: 600; }

.search-toolbar { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.export-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.export-bar label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* ---------- print ---------- */

.print-page { max-width: 800px; margin: 0 auto; }
.print-page table { width: 100%; border-collapse: collapse; }
.print-page td { padding: 8px; border-bottom: 1px solid #ddd; vertical-align: top; }
.print-page td.k { font-weight: bold; width: 220px; color: #444; }
.print-toolbar { margin-bottom: 20px; }

@media print {
  .no-print { display: none !important; }
  .topbar, .sidebar { display: none !important; }
  .main { padding: 0; }
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--navy-900), var(--navy-700));
}
.login-box {
  background: var(--panel); border-radius: var(--radius);
  padding: 34px; width: 340px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-box .brand { display: flex; align-items: center; gap: 8px; color: var(--teal-dark); font-size: 19px; font-weight: 700; margin-bottom: 18px; }
.login-box input {
  width: 100%; padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px;
}
.login-box input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-bg); }
.error-msg { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }

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

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -260px; top: 60px; bottom: 0; transition: left .18s; z-index: 30; }
  .sidebar.open { left: 0; }
  .topbar .menu-toggle { display: flex; }
  form.record-form { grid-template-columns: 1fr; }
}
