:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e4e9f0;
  --ink: #16202c;
  --ink-soft: #5b6b7d;
  --muted: #8a97a6;
  --brand: #0b3d63;
  --brand-2: #0e5c8a;
  --accent: #0ea5a8;
  --danger: #d64545;
  --warn: #c77700;
  --ok: #2e9e5b;
  --shadow: 0 1px 2px rgba(16,32,44,.06), 0 4px 16px rgba(16,32,44,.06);
  --shadow-lg: 0 10px 40px rgba(16,32,44,.18);
  --radius: 14px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; background: var(--surface-2); color: var(--ink);
  transition: .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-logout { background: #64748b; color: #fff; border-color: #64748b; }
.btn-logout:hover { background: #51606f; border-color: #51606f; filter: none; }
.btn-block { width: 100%; padding: 11px; margin-top: 4px; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-ghost:hover { background: #fbeaea; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer; font-size: 18px;
  color: var(--ink-soft); padding: 6px 9px; border-radius: 8px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #0e5c8a22, transparent),
              linear-gradient(160deg, #0b3d63 0%, #0e5c8a 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 6px; }
.login-logo { font-size: 42px; }
.login-card h1 { font-size: 21px; margin: 6px 0 2px; color: var(--brand); }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; color: var(--ink-soft); }
.login-card input, .login-card select {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2); width: 100%;
}
.login-card input:focus, .login-card select:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
.login-hint { font-size: 12.5px; text-align: center; margin-top: 2px; line-height: 1.6; }
.login-credit { font-size: 11.5px; text-align: center; color: var(--muted); font-style: italic; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.error { color: var(--danger); font-size: 13px; margin: 0; text-align: center; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 18px; height: 60px;
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { font-size: 24px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15.5px; }
.brand-text .muted { color: #bcd4e6; font-size: 11.5px; }
.settings-btn { color: #fff; font-size: 17px; }
.settings-btn:hover { background: #ffffff22; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.role-badge {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 3px 8px; border-radius: 999px; background: var(--accent); color: #fff;
}
.role-badge.viewer { background: #ffffff2e; }
.menu-toggle { color: #fff; display: none; font-size: 22px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
  width: 250px; background: var(--surface); border-right: 1px solid var(--line);
  padding: 14px 10px; flex-shrink: 0; overflow-y: auto;
  position: sticky; top: 60px; height: calc(100vh - 60px);
}
.nav-group-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px;
  cursor: pointer; color: var(--ink-soft); font-weight: 500; font-size: 14px;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: #0b3d630f; color: var(--brand); font-weight: 600; }
.nav-ico {
  width: 26px; height: 26px; flex-shrink: 0; display: grid; place-items: center;
  border-radius: 7px; background: var(--surface-2); font-size: 15px;
}
.nav-item.active .nav-ico { background: #0b3d6318; }
.nav-count { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 600; }

.scrim { display: none; }
.content { flex: 1; padding: 24px 28px 60px; min-width: 0; }

/* ---------- page header ---------- */
.page-head { margin-bottom: 18px; }
.page-head h2 { margin: 0 0 3px; font-size: 22px; }
.page-head p { margin: 0; color: var(--muted); }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin: 16px 0;
}
.search {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.search input { border: none; outline: none; font: inherit; flex: 1; background: transparent; }
select.filter {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface);
}

/* ---------- overview ---------- */
.hero {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  color: #fff; border-radius: var(--radius); padding: 22px 24px; margin-bottom: 22px;
  display: flex; flex-wrap: wrap; gap: 20px; align-items: center; box-shadow: var(--shadow);
}
.hero h2 { margin: 0 0 4px; font-size: 20px; }
.hero p { margin: 0; color: #cfe2f0; font-size: 13.5px; }
.hero-credit {
  font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  font-style: italic; font-weight: 600;
  font-size: 17px; letter-spacing: .3px; color: #eaf3fa !important;
  margin-top: 8px !important; opacity: .95;
}
.hero-contacts { margin-left: auto; display: flex; gap: 12px; flex-wrap: wrap; }
.hero-contact {
  background: #ffffff1f; border: 1px solid #ffffff33; border-radius: 12px;
  padding: 10px 16px; color: #fff; min-width: 130px;
}
.hero-contact span { display: block; font-size: 11px; color: #cfe2f0; }
.hero-contact strong { font-size: 17px; }
.hero-contact:hover { background: #ffffff33; text-decoration: none; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 10px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: .15s; box-shadow: var(--shadow);
}
.stat-card:hover { transform: translateY(-2px); border-color: #cdd8e3; }
.stat-ico {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 19px; background: #0b3d630f; margin-bottom: 10px;
}
.stat-num { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 3px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 26px 0 12px; }

/* ---------- data table ---------- */
/* overflow must stay visible so the sticky <thead> sticks to the viewport
   (an overflow:hidden/auto ancestor would capture the scroll and break it). */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 11px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 60px; z-index: 10;
}
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child { border-top-right-radius: var(--radius); }
tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top;
  white-space: pre-line; overflow-wrap: anywhere; word-break: break-word;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
tbody tr:hover { background: var(--surface-2); }
.cell-primary { font-weight: 600; }
.mandal-tag {
  display: inline-block; font-size: 11.5px; font-weight: 600; color: var(--brand-2);
  background: #0e5c8a14; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
td.actions { white-space: nowrap; text-align: right; }
.row-actions { display: inline-flex; gap: 2px; opacity: .35; transition: .15s; }
tr:hover .row-actions { opacity: 1; }
.phone-link { color: var(--brand-2); font-weight: 500; display: block; }

.group-header td {
  background: #eef3f8; font-weight: 700; color: var(--brand);
  font-size: 12.5px; letter-spacing: .3px; padding-top: 9px; padding-bottom: 9px;
}
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.count-pill { color: var(--muted); font-size: 13px; font-weight: 600; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: #0b1f3199; display: grid; place-items: center; z-index: 60; padding: 18px; }
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 13px; }
.modal-body label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12.5px; color: var(--ink-soft); }
.modal-body input, .modal-body textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface-2); resize: vertical;
}
.modal-body input:focus, .modal-body textarea:focus { outline: 2px solid var(--brand-2); border-color: transparent; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-note { margin: 0 0 2px; color: var(--muted); font-size: 12.5px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-weight: 600; font-size: 13.5px; z-index: 80; box-shadow: var(--shadow-lg);
}
.toast.err { background: var(--danger); }

/* ---------- password show/hide ---------- */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--muted);
  padding: 5px; display: grid; place-items: center; border-radius: 6px; line-height: 0;
}
.pw-toggle:hover { color: var(--ink); background: var(--surface-2); }
.pw-toggle svg { display: block; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 60px; z-index: 40; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; position: fixed; inset: 60px 0 0 0; background: #0008; z-index: 35; }
  .content { padding: 18px 16px 50px; }
  .topbar-right .user-chip span:first-child { display: none; }
  .hero-contacts { margin-left: 0; width: 100%; }
  /* On phones, sticky headers are dropped and the table scrolls sideways
     inside its card so narrow columns don't crush. */
  thead th { position: static; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 680px; }
}
