/* ==========================================================
   shared.css – ECG GroupSync  |  nav + global base + components
   ========================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:       #f9fafb;
  --surface:  #ffffff;
  --line:     #e5e7eb;
  --text:     #111827;
  --muted:    #6b7280;
  --hover:    #f3f4f6;
  --accent:   #00A7DE;
  --accent-h: #0090bf;
  --accent-bg:#e0f2fe;
  --accent-fg:#0369a1;
  --danger:   #ef4444;
  --success:  #22c55e;
  --radius:   12px;
  --nav-h:    52px;
}

html, body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── NAV ───────────────────────────────────────────────────── */
.app-nav {
  position: sticky; top: 0; z-index: 200;
  display: flex; align-items: center;
  padding: 0 16px; height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  gap: 4px;
}
.nav-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; color: var(--text);
  font-weight: 700; font-size: 15px; flex-shrink: 0; margin-right: 6px;
}
.nav-logo img { width: 26px; height: 26px; object-fit: contain; display: block; }
.nav-links { display: flex; align-items: center; gap: 2px; flex: 1; }
.nav-link {
  display: inline-flex; align-items: center;
  padding: 6px 12px; border-radius: 999px;
  text-decoration: none; font-size: 14px; font-weight: 500;
  color: var(--muted); white-space: nowrap;
  transition: background .12s, color .12s;
}
.nav-link:hover  { background: var(--hover); color: var(--text); }
.nav-link.active { background: var(--accent-bg); color: var(--accent-fg); font-weight: 600; }

.nav-dropdown { position: relative; }
.nav-dropdown-trigger { cursor: pointer; gap: 4px; border: none; font-family: inherit; font-size: inherit; }
.nav-dropdown-trigger svg { transition: transform .15s; flex-shrink: 0; }
.nav-dropdown.open .nav-dropdown-trigger svg { transform: rotate(180deg); }
.nav-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 170px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 4px; z-index: 300; flex-direction: column; gap: 2px;
}
.nav-dropdown.open .nav-dropdown-menu { display: flex; }
.nav-dropdown-item { border-radius: 7px; padding: 9px 12px; font-size: 14px; }

.nav-mobile-admin-section { padding-top: 2px; }
.nav-mobile-admin-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); padding: 8px 14px 4px;
}
.nav-mobile-link--sub { padding-left: 26px; font-size: 14px; }

.nav-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.nav-user-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px 5px 5px; border-radius: 999px;
  text-decoration: none; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--hover);
  border: 1px solid var(--line); transition: all .12s; cursor: pointer;
}
.nav-user-btn:hover { background: var(--accent-bg); border-color: rgba(0,167,222,.4); color: var(--accent-fg); }
.nav-avatar {
  width: 24px; height: 24px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; letter-spacing: .03em;
}
.nav-logout-btn {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  color: var(--muted); background: transparent; border: 1px solid var(--line);
  cursor: pointer; transition: all .12s;
}
.nav-logout-btn:hover { background: var(--hover); color: var(--text); }
.nav-login-btn {
  display: inline-flex; align-items: center; padding: 7px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; background: var(--accent); color: #fff;
  text-decoration: none; border: none; cursor: pointer; transition: background .12s;
}
.nav-login-btn:hover { background: var(--accent-h); }
.nav-hamburger {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; transition: all .12s;
  color: var(--muted); margin-left: auto; flex-shrink: 0;
}
.nav-hamburger:hover { background: var(--hover); border-color: var(--accent); color: var(--accent); }
.nav-mobile-menu {
  display: none; position: fixed; top: var(--nav-h); left: 0; right: 0;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 8px 12px 12px; flex-direction: column; gap: 3px; z-index: 199;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.nav-mobile-menu.open { display: flex; }
.nav-mobile-link {
  display: flex; align-items: center; padding: 11px 14px; border-radius: 10px;
  text-decoration: none; font-size: 15px; font-weight: 500; color: var(--text);
  transition: background .12s;
}
.nav-mobile-link:hover, .nav-mobile-link.active { background: var(--accent-bg); color: var(--accent-fg); }
.nav-mobile-sep { height: 1px; background: var(--line); margin: 4px 0; }
.nav-mobile-action {
  display: flex; align-items: center; padding: 11px 14px; border-radius: 10px;
  font-size: 15px; font-weight: 500; color: var(--muted); background: transparent;
  border: none; cursor: pointer; width: 100%; text-align: left; text-decoration: none;
  transition: background .12s;
}
.nav-mobile-action:hover { background: var(--hover); color: var(--text); }
.nav-mobile-action--accent { color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .nav-links, .nav-right { display: none !important; }
  .nav-hamburger { display: flex; }
}

/* ── PAGE UTILITIES ────────────────────────────────────────── */
.page-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 20px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; color: var(--text); }
.page-sub { color: var(--muted); font-size: 14px; margin: -12px 0 20px; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card h2 { font-size: 16px; font-weight: 700; margin: 0 0 16px; color: var(--text); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 540px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select {
  height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px;
  transition: border-color .12s, box-shadow .12s; outline: none; width: 100%;
}
.field textarea {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px;
  resize: vertical; outline: none; width: 100%; min-height: 70px;
  transition: border-color .12s, box-shadow .12s; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,167,222,.12);
}
.field input:disabled { opacity: .55; cursor: not-allowed; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  border: none; cursor: pointer; transition: all .12s; white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-h); }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn--ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn--danger { background: rgba(239,68,68,.1); color: #b91c1c; border: 1px solid rgba(239,68,68,.25); }
.btn--danger:hover:not(:disabled) { background: rgba(239,68,68,.18); }

.form-msg { margin-top: 10px; padding: 10px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; }
.form-msg--success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.form-msg--error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.muted-text { color: var(--muted); font-size: 14px; }

/* ── TOOLBAR (search + filters + actions) ──────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input {
  width: 100%; height: 42px; padding: 0 12px 0 38px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 14px; outline: none; transition: border-color .12s, box-shadow .12s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,167,222,.12); }
.search-box svg { position: absolute; left: 13px; top: 12px; color: var(--muted); }
.toolbar select {
  height: 42px; padding: 0 30px 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer; outline: none;
}
.btn-group { display: flex; gap: 6px; align-items: center; }

/* ── TABLE ─────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow-x: auto;
}
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl thead th {
  text-align: left; padding: 12px 14px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
}
table.tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: var(--hover); }
.cell-name { font-weight: 600; color: var(--text); }
.cell-actions { text-align: right; white-space: nowrap; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; transition: all .12s; margin-left: 4px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); border-color: var(--accent); }
.icon-btn--danger:hover { color: #b91c1c; border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.08); }

.empty-state { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-state svg { opacity: .4; margin-bottom: 12px; }

/* ── CHIPS / BADGES ────────────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5;
  background: var(--accent-bg); color: var(--accent-fg);
}
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip--select {
  cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  user-select: none; transition: all .12s;
}
.chip--select.on { background: var(--accent-bg); color: var(--accent-fg); border-color: transparent; }
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-transform: capitalize;
}
.badge--admin   { background: #fae8ff; color: #86198f; }
.badge--manager { background: #dbeafe; color: #1e40af; }
.badge--viewer  { background: var(--hover); color: var(--muted); }

/* ── MODAL ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 400; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); padding: 24px;
}
.modal-head { display: flex; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-size: 18px; font-weight: 700; margin: 0; }
.modal-close {
  margin-left: auto; width: 32px; height: 32px; border-radius: 8px; border: none;
  background: var(--hover); color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.modal-close:hover { background: var(--line); color: var(--text); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* ── DARK MODE ─────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0d1117; --surface:#161e2e; --line:#2a3a52; --text:#e8edf3;
    --muted:#8899b0; --hover:#1d2a3f; --accent-bg:rgba(0,167,222,.18); --accent-fg:#38bdf8;
  }
  .field input, .field select, .field textarea, .search-box input, .toolbar select {
    background:#0d1420; border-color:#2a3a52; color: var(--text);
  }
  .field input::placeholder, .field textarea::placeholder, .search-box input::placeholder { color:#4a5a70; }
  .nav-logo img { filter: invert(1) brightness(1.2); }
  .form-msg--success { background: rgba(34,197,94,.12); color:#86efac; border-color: rgba(34,197,94,.3); }
  .form-msg--error   { background: rgba(239,68,68,.14); color:#fca5a5; border-color: rgba(239,68,68,.35); }
  .badge--admin   { background: rgba(168,85,247,.2); color:#e9d5ff; }
  .badge--manager { background: rgba(59,130,246,.2); color:#bfdbfe; }
  .modal { box-shadow: 0 20px 60px rgba(0,0,0,.6); }
}
