@charset "UTF-8";
/* =============================================================================
   Indian OncoCare — Admin Console
   Phase B design system.

   Cache: layout_header.php stamps this file with filemtime(), so the browser
   picks up an edit on the next request. The old hardcoded "?v=1" combined with
   the root .htaccess rule `ExpiresByType text/css "access plus 1 month"` is why
   the console had been rendering with a month-old stylesheet.

   Notes for whoever edits this next:
   - System fonts on purpose. This is a tool that gets opened between
     consultations, sometimes on hospital wifi. A webfont buys personality and
     costs a flash of unstyled text on every page. Not a trade worth making.
     Character comes from the type scale, the numerals, and the green.
   - Tables become cards under 860px. Markup drives it: every <td> needs a
     data-label attribute. See the "Responsive tables" block.
   - Legacy class names from the earlier build are all still supported, so
     staff.php / referrals.php / statistics.php keep working untouched.
   ========================================================================== */

/* ---- 1. Tokens ----------------------------------------------------------- */
:root {
  /* Brand — unchanged from the original console. */
  --accent:        #0e7c66;
  --accent-dark:   #0a5d4c;
  --accent-soft:   #ecfdf5;
  --accent-line:   #a7f3d0;
  --sidebar:       #0b2e28;
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-ink:   #cfe8e1;
  --sidebar-dim:   #7ba79c;

  /* Neutrals, warmed a few degrees toward the green so the greys sit with the
     brand instead of next to it. */
  --ink:      #16211f;
  --ink-2:    #46534f;
  --muted:    #6b7975;
  --line:     #e3e9e7;
  --line-2:   #eef2f1;
  --bg:       #f1f4f4;
  --card:     #ffffff;
  --hover:    #f7faf9;

  --danger:      #b42318;
  --danger-soft: #fef3f2;
  --danger-line: #fecdca;
  --warn:        #b54708;
  --warn-soft:   #fffaeb;
  --warn-line:   #fedf89;
  --info:        #175cd3;
  --info-soft:   #eff8ff;
  --ok:          var(--accent);

  --r-sm: 8px;
  --r:    10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --pill: 999px;

  --sh-1: 0 1px 2px rgba(16,32,28,.05);
  --sh-2: 0 2px 8px rgba(16,32,28,.06), 0 1px 2px rgba(16,32,28,.04);
  --sh-3: 0 12px 32px rgba(16,32,28,.12);
  --sh-pop: 0 20px 60px rgba(11,46,40,.28);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --side-w: 232px;
  --tap:    44px;   /* minimum touch target */
}

/* ---- 2. Base ------------------------------------------------------------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* Numbers line up in columns and don't jitter as they tick. */
.data-table td, .card-num, .kv-v, .metric-num, .chat-time, .tabular { font-variant-numeric: tabular-nums; }

code, pre, .mono { font-family: var(--mono); font-size: .85em; }

/* One visible focus ring for the whole console. Keyboard users can see where
   they are; mouse users never see it. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-line); color: var(--ink); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- 3. Login ------------------------------------------------------------ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; padding: 20px;
  background: linear-gradient(150deg, var(--accent) 0%, var(--sidebar) 100%);
}
.login-card {
  background: #fff; width: 380px; max-width: 100%;
  padding: 30px 28px; border-radius: var(--r-xl); box-shadow: var(--sh-pop);
}
.login-brand, .brand {
  font-weight: 700; font-size: 1.18rem; color: var(--accent);
  display: flex; flex-direction: column; line-height: 1.25; margin-bottom: 18px;
  letter-spacing: -.015em;
}
.login-brand span, .brand span {
  font-size: .68rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .09em; margin-top: 3px;
}
.login-card label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: var(--r); font-size: .95rem; font-family: inherit; background: #fff;
}
.login-card input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- 4. Shell ------------------------------------------------------------ */
.admin-wrap { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: var(--side-w); flex-shrink: 0;
  background: var(--sidebar); color: var(--sidebar-ink);
  padding: 20px 12px; display: flex; flex-direction: column;
}
.sidebar .brand { color: #fff; padding: 0 8px; }
.sidebar .brand span { color: var(--sidebar-dim); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 20px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-ink); padding: 10px 12px; border-radius: var(--r-sm);
  font-size: .92rem; font-weight: 500; min-height: 40px;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-item.disabled { color: #567f76; cursor: default; }
.nav-item.disabled em {
  font-style: normal; font-size: .62rem; background: #123f38;
  padding: 2px 7px; border-radius: var(--pill); margin-left: 4px;
}
.nav-ico { width: 18px; text-align: center; flex-shrink: 0; opacity: .9; font-size: .95rem; }
.nav-item.active .nav-ico { opacity: 1; }

/* Unread counter on the Inbox item (Phase E). */
.nav-count {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: .66rem; font-weight: 700; min-width: 19px; height: 19px;
  border-radius: var(--pill); display: inline-flex;
  align-items: center; justify-content: center; padding: 0 5px;
}
.nav-item.active .nav-count { background: #fff; color: var(--accent-dark); }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; font-size: .7rem; color: var(--sidebar-dim); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 10px 22px; position: sticky; top: 0; z-index: 30;
}
.who { font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: 6px; min-width: 0; }
.who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.role {
  font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 8px; border-radius: var(--pill); background: var(--line-2); color: var(--muted);
}
.role-admin { background: var(--accent); color: #fff; }
.role-staff { background: #e0e7ff; color: #3730a3; }
.logout { font-size: .86rem; color: var(--danger); font-weight: 500; padding: 6px 4px; }

/* Drawer toggle — hidden until the sidebar goes off-canvas. */
.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); margin-left: -10px;
  background: none; border: 0; border-radius: var(--r-sm);
  cursor: pointer; color: var(--ink);
}
.nav-toggle:hover { background: var(--line-2); }
.nav-toggle svg { width: 21px; height: 21px; }
.scrim {
  display: none; position: fixed; inset: 0; z-index: 45;
  background: rgba(11,46,40,.45); backdrop-filter: blur(2px);
}

.content { padding: 24px 26px 40px; flex: 1; min-width: 0; }
.admin-foot {
  padding: 14px 26px; color: var(--muted); font-size: .76rem;
  border-top: 1px solid var(--line);
}

/* ---- 5. Type + page head ------------------------------------------------- */
h1 { font-size: 1.42rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 1.02rem; font-weight: 650; letter-spacing: -.01em; margin: 24px 0 10px; }
h3 { font-size: .9rem;  font-weight: 650; margin: 18px 0 8px; }

.muted { color: var(--muted); }
.hint  { color: var(--muted); font-size: .8rem; line-height: 1.5; }
.page-sub { color: var(--muted); font-size: .88rem; margin: 2px 0 0; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.count-chip {
  font-size: .76rem; font-weight: 650; color: var(--muted);
  background: var(--line-2); border-radius: var(--pill); padding: 3px 9px;
}

.detail-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.detail-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }

.crumb { font-size: .82rem; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }

/* ---- 6. Buttons ---------------------------------------------------------- */
.btn, .btn-sm, .btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: #fff;
  color: var(--ink-2); transition: background .12s ease, border-color .12s ease, color .12s ease;
  text-decoration: none;
}
.btn { padding: 8px 14px; font-size: .86rem; min-height: 38px; }
.btn-sm { padding: 6px 11px; font-size: .8rem; min-height: 32px; }
.btn:hover, .btn-sm:hover { background: var(--hover); border-color: #d4dcd9; color: var(--ink); text-decoration: none; }

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  padding: 9px 16px; font-size: .88rem; min-height: 38px;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; text-decoration: none; }

.btn-danger { background: #fff; border-color: var(--danger-line); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--line-2); color: var(--ink); }

.btn:disabled, .btn-primary:disabled, .btn-sm:disabled,
.btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-block { width: 100%; }
.btn-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* The original stylesheet made .btn-primary full-width, so pages worked around
   it with inline style="width:auto". Buttons are now inline by default and
   those inline styles are simply redundant — nothing to clean up urgently. */

/* ---- 7. Forms ------------------------------------------------------------ */
label { font-size: .8rem; font-weight: 600; color: var(--ink-2); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-req::after { content: " *"; color: var(--danger); font-weight: 700; }

input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; font-family: inherit; font-size: .9rem;
  color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-sm); min-height: 38px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.55; }

input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled, textarea:disabled { background: var(--line-2); color: var(--muted); cursor: not-allowed; }
input::placeholder, textarea::placeholder { color: #9aa8a4; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7975' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  background-size: 10px; padding-right: 30px;
}

.check { display: flex; align-items: flex-start; gap: 8px; font-size: .86rem; font-weight: 500; color: var(--ink-2); }
.check input[type=checkbox], .check input[type=radio] {
  width: 16px; height: 16px; min-height: 0; margin: 2px 0 0; accent-color: var(--accent); flex-shrink: 0;
}

.form-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--sh-1);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2);
}
.form-section-title {
  grid-column: 1 / -1; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin: 6px 0 -4px;
}

/* Legacy form classes. */
.stack-form { max-width: 520px; display: flex; flex-direction: column; gap: 10px; background: #fff; border: 1px solid var(--line); padding: 18px; border-radius: var(--r-lg); }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-form { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; max-width: 340px; }
.mini-form label { font-size: .78rem; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

/* Phone field with a country-code select welded to the left. */
.phone-group { display: flex; }
.phone-group select {
  width: 108px; flex-shrink: 0; border-radius: var(--r-sm) 0 0 var(--r-sm); border-right: 0;
}
.phone-group input { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.phone-group select:focus, .phone-group input:focus { position: relative; z-index: 1; }

/* ---- 8. Toolbar ---------------------------------------------------------- */
.toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 10px 12px; margin-bottom: 14px; box-shadow: var(--sh-1);
}
.toolbar-grow { flex: 1; min-width: 180px; }
.toolbar-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }

.search-field { position: relative; flex: 1; min-width: 190px; }
.search-field input { padding-left: 34px; }
.search-field::before {
  content: "⌕"; position: absolute; left: 12px; top: 50%; transform: translateY(-52%);
  color: var(--muted); font-size: 1.05rem; pointer-events: none;
}

/* Legacy filter bar. */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; align-items: center; }
.filter-bar select, .filter-bar input { width: auto; }
.filter-bar input { min-width: 220px; }

.seg { display: inline-flex; background: var(--line-2); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg a {
  padding: 6px 12px; font-size: .8rem; font-weight: 600; color: var(--muted);
  border-radius: 6px; white-space: nowrap;
}
.seg a:hover { color: var(--ink); text-decoration: none; }
.seg a.on { background: #fff; color: var(--accent); box-shadow: var(--sh-1); }

/* ---- 9. Tables ----------------------------------------------------------- */
.table-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); overflow: hidden;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table { width: 100%; border-collapse: collapse; background: #fff; }
/* Standalone tables (not wrapped in .table-card) keep their own frame. */
.data-table:not(.table-card .data-table) {
  border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden;
}

.data-table th, .data-table td {
  padding: 11px 14px; text-align: left; font-size: .88rem;
  border-bottom: 1px solid var(--line-2); vertical-align: middle;
}
.data-table th {
  background: #f8faf9; color: var(--muted); font-weight: 700;
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
  border-bottom: 1px solid var(--line);
}
.data-table tbody tr { transition: background .1s ease; }
.data-table tbody tr:hover { background: var(--hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td.num { text-align: right; }
.data-table td.tight { width: 1%; white-space: nowrap; }

/* Sortable headers. */
.data-table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.data-table th a:hover { color: var(--accent); text-decoration: none; }
.data-table th a::after { content: "↕"; opacity: .35; font-size: .8em; }
.data-table th a.asc::after  { content: "↑"; opacity: 1; color: var(--accent); }
.data-table th a.desc::after { content: "↓"; opacity: 1; color: var(--accent); }

.row-id { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-actions input[type=password] { width: 130px; min-height: 32px; padding: 6px 8px; font-size: .8rem; }

/* Name + email stacked in one cell. */
.cell-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.cell-person-txt { min-width: 0; }
.cell-name { font-weight: 600; color: var(--ink); display: block; overflow: hidden; text-overflow: ellipsis; }
.cell-sub {
  display: block; font-size: .76rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px;
}
.cell-wrap { max-width: 200px; white-space: normal; line-height: 1.35; }

.empty-state { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-state .empty-ico { font-size: 1.8rem; display: block; margin-bottom: 8px; opacity: .5; }
.empty-state p { margin: 0 0 14px; font-size: .9rem; }

/* Responsive tables — cards under 860px.
   Requires data-label on each <td>. A <td> with no data-label just renders
   its value on a full-width row, which is what you want for actions. */
@media (max-width: 860px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px;
    padding: 4px 2px; background: #fff; box-shadow: var(--sh-1);
  }
  .data-table tbody tr:hover { background: #fff; }
  .data-table td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
    padding: 8px 12px; border-bottom: 1px solid var(--line-2); text-align: right;
  }
  .data-table td:last-child { border-bottom: 0; }
  .data-table td::before {
    content: attr(data-label);
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); text-align: left; flex-shrink: 0; padding-top: 2px;
  }
  .data-table td:not([data-label]) { justify-content: flex-start; text-align: left; }
  .data-table td.cell-actions { justify-content: flex-end; }
  .data-table td.cell-actions::before { content: none; }
  .cell-sub { max-width: none; }
  .cell-wrap { max-width: none; text-align: right; }
  .table-card { border: 0; background: none; box-shadow: none; border-radius: 0; }
  .table-scroll { overflow: visible; }
  .empty-state { background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
}

/* ---- 10. Badges, pills, avatars ------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .72rem; font-weight: 700; padding: 3px 10px;
  border-radius: var(--pill); white-space: nowrap; letter-spacing: .01em;
}
.st-new        { background: #e0f2fe; color: #075985; }
.st-contacted  { background: #fef3c7; color: #92400e; }
.st-progress   { background: #ede9fe; color: #5b21b6; }
.st-converted  { background: #dcfce7; color: #166534; }
.st-nointerest { background: #f3f4f6; color: #4b5563; }
.st-closed     { background: #e5e7eb; color: #374151; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 600; padding: 3px 9px; border-radius: var(--pill); }
.pill.ok   { background: var(--accent-soft); color: var(--accent-dark); }
.pill.off  { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.neutral { background: var(--line-2); color: var(--muted); }

/* The 24h WhatsApp window, as a first-class readout. Staff need to know at a
   glance whether they can type freely or must send a template. */
.win { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 650; white-space: nowrap; }
.win::before { content: ""; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.win.open   { color: var(--accent-dark); }
.win.open::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.win.closed { color: var(--muted); }
.win.closed::before { background: #c3cecb; }
.win.soon   { color: var(--warn); }
.win.soon::before { background: #f79009; box-shadow: 0 0 0 3px var(--warn-soft); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .74rem; font-weight: 700; letter-spacing: .02em; color: #fff;
  background: var(--accent); user-select: none;
}
.avatar-lg { width: 48px; height: 48px; font-size: .95rem; }
.avatar-sm { width: 28px; height: 28px; font-size: .64rem; }
/* Stable per-person tones — the same name always gets the same swatch, so the
   list becomes scannable by colour once you know your regulars. */
.tone-1 { background: #0e7c66; }
.tone-2 { background: #2563eb; }
.tone-3 { background: #7c3aed; }
.tone-4 { background: #b54708; }
.tone-5 { background: #be123c; }
.tone-6 { background: #0f766e; }

.dot-new {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--info); flex-shrink: 0;
}

/* ---- 11. Panels ---------------------------------------------------------- */
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px 20px; box-shadow: var(--sh-1);
}
.panel h2, .panel-title {
  margin: 0 0 14px; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.panel-title.with-action { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel + .panel { margin-top: 18px; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush .panel-title { padding: 16px 20px 0; }

.detail-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; align-items: start; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; align-items: start; }

/* Label/value rows.
   The old rule was `.fld { display:flex }` with a fixed-width label — which is
   what collapsed to "NameAhmed Khan" once the stylesheet went stale. This is a
   grid, so label and value can never run together even unstyled. */
.kv-list, .fld-list { display: flex; flex-direction: column; }
.kv, .fld {
  display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px;
  padding: 9px 0; border-bottom: 1px solid var(--line-2); align-items: baseline;
}
.kv:last-child, .fld:last-child { border-bottom: 0; }
.kv-k, .fld-l { color: var(--muted); font-size: .8rem; font-weight: 600; }
.kv-v, .fld-v { font-size: .89rem; color: var(--ink); min-width: 0; word-break: break-word; }
.kv-v .hint { display: block; margin-top: 2px; }

@media (max-width: 560px) {
  .kv, .fld { grid-template-columns: 1fr; gap: 2px; padding: 10px 0; }
}

/* ---- 12. Metric cards ---------------------------------------------------- */
.cards, .metrics {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 14px; margin: 18px 0;
}
.card, .metric {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 18px; box-shadow: var(--sh-1); min-width: 0;
  transition: border-color .12s ease, box-shadow .12s ease;
}
a.card:hover, a.metric:hover { border-color: var(--accent-line); box-shadow: var(--sh-2); text-decoration: none; }
.card-num, .metric-num {
  display: block; font-size: 1.75rem; font-weight: 700;
  color: var(--accent); letter-spacing: -.03em; line-height: 1.15;
}
.card-label, .metric-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.metric-alert .metric-num { color: var(--danger); }

.phase-note {
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  color: var(--accent-dark); padding: 12px 14px; border-radius: var(--r);
  font-size: .88rem; margin-top: 10px;
}

/* ---- 13. Flash ----------------------------------------------------------- */
.flash {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 14px; border-radius: var(--r); font-size: .88rem;
  margin-bottom: 14px; border: 1px solid transparent; line-height: 1.5;
}
.flash.info, .flash.ok { background: var(--accent-soft); color: var(--accent-dark); border-color: var(--accent-line); }
.flash.error   { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.flash.warn    { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.flash strong  { font-weight: 700; }

.log-out {
  background: #0b2e28; color: #cfe8e1; padding: 14px; border-radius: var(--r);
  font-size: .76rem; line-height: 1.6; overflow-x: auto; margin: 0;
  white-space: pre-wrap; word-break: break-word;
}

/* Confirm-before-destroying. */
.danger-zone { border-color: var(--danger-line); }
.danger-zone .panel-title { color: var(--danger); }

/* ---- 14. Chat / conversation --------------------------------------------- */
.chat-window {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-lg);
  display: flex; flex-direction: column; height: calc(100vh - 220px);
  min-height: 420px; overflow: hidden; box-shadow: var(--sh-1);
}
.chat-thread {
  flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px;
  background: #eceff0;
  /* A faint paper tint rather than a flat grey, so the bubbles read as sitting
     on something. Cheap, no image request. */
  background-image: radial-gradient(circle at 1px 1px, rgba(11,46,40,.045) 1px, transparent 0);
  background-size: 22px 22px;
  overscroll-behavior: contain;
}
.chat-row { display: flex; }
.chat-row.in  { justify-content: flex-start; }
.chat-row.out { justify-content: flex-end; }
.chat-bubble {
  max-width: 72%; padding: 8px 11px 6px; border-radius: var(--r);
  font-size: .89rem; line-height: 1.45; box-shadow: 0 1px 1px rgba(16,32,28,.08);
  word-break: break-word;
}
.chat-row.in  .chat-bubble { background: #fff; border-bottom-left-radius: 3px; }
.chat-row.out .chat-bubble { background: #d9fdd3; border-bottom-right-radius: 3px; }
.chat-row.out .chat-bubble.failed { background: var(--danger-soft); border: 1px solid var(--danger-line); }
.chat-time {
  display: flex; align-items: center; justify-content: flex-end; gap: 4px;
  font-size: .64rem; color: #67757180; color: rgba(70,83,79,.7); margin-top: 3px;
}
.chat-sys {
  align-self: center; background: #fff8e6; border: 1px solid var(--warn-line);
  color: #7c5b12; font-size: .79rem; padding: 7px 12px; border-radius: var(--r);
  max-width: 84%; text-align: center; line-height: 1.45;
}
.chat-sys .chat-time { justify-content: center; }

/* Delivery ticks. */
.tick { font-size: .72rem; letter-spacing: -2px; }
.tick.sent      { color: var(--muted); }
.tick.delivered { color: var(--muted); }
.tick.read      { color: #2563eb; }
.tick.failed    { color: var(--danger); letter-spacing: 0; }

.chat-media { display: block; max-width: 240px; border-radius: 6px; margin-bottom: 5px; }
.chat-file {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin-bottom: 4px;
  background: rgba(11,46,40,.06); border-radius: 6px; color: var(--ink);
}
.chat-file:hover { background: rgba(11,46,40,.1); text-decoration: none; }
.chat-file-ico { font-size: 1.2rem; flex-shrink: 0; }
.chat-file-name { font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-meta { font-size: .7rem; color: var(--muted); }

.chat-daysep {
  align-self: center; background: rgba(255,255,255,.9); color: var(--muted);
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 12px; border-radius: var(--pill); margin: 6px 0;
}

.chat-compose { border-top: 1px solid var(--line); padding: 12px 14px; background: #fff; }
.win-banner {
  display: flex; align-items: center; gap: 7px;
  font-size: .79rem; padding: 7px 11px; border-radius: var(--r-sm); margin-bottom: 9px; line-height: 1.45;
}
.win-banner.ok     { background: var(--accent-soft); color: var(--accent-dark); border: 1px solid var(--accent-line); }
.win-banner.closed { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }
.compose-form { display: flex; gap: 8px; align-items: center; }
.compose-form input[type=text] { flex: 1; border-radius: var(--pill); padding: 10px 14px; }
.attach {
  cursor: pointer; font-size: 1.15rem; flex-shrink: 0;
  width: var(--tap); height: var(--tap); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.attach:hover { background: var(--line-2); color: var(--ink); }
.attach input[type=file] { display: none; }
.tpl-preview { font-size: .84rem; color: var(--muted); margin-bottom: 8px; }

/* ---- 15. Attachments list ------------------------------------------------ */
.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-row {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff;
}
.file-row:hover { border-color: var(--accent-line); background: var(--hover); }
.file-ico { font-size: 1.25rem; flex-shrink: 0; }
.file-meta { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.file-sub  { font-size: .74rem; color: var(--muted); }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--r); padding: 20px;
  text-align: center; color: var(--muted); font-size: .85rem; background: #fbfdfc;
  transition: border-color .12s ease, background .12s ease; cursor: pointer;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }

/* ---- 16. Statistics ------------------------------------------------------ */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; align-items: start; }
.barrow { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.barlbl { width: 150px; flex-shrink: 0; font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bartrack { flex: 1; height: 13px; background: var(--line-2); border-radius: var(--pill); overflow: hidden; }
.barfill { display: block; height: 100%; background: var(--accent); border-radius: var(--pill); transition: width .3s ease; }
.barval { width: 34px; text-align: right; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- 17. Pager ----------------------------------------------------------- */
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager .muted { font-size: .84rem; }

/* ---- 18. Utilities ------------------------------------------------------- */
.stack   { display: flex; flex-direction: column; gap: 10px; }
.row     { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.grow    { flex: 1; min-width: 0; }
.nowrap  { white-space: nowrap; }
.mt-0 { margin-top: 0; }  .mt-1 { margin-top: 8px; }  .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.text-danger { color: var(--danger); }
.text-ok { color: var(--accent-dark); }
.divider { height: 1px; background: var(--line-2); border: 0; margin: 16px 0; }

/* ---- 19. Responsive ------------------------------------------------------ */
@media (max-width: 1080px) {
  .detail-grid, .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 860px) {
  /* Sidebar goes off-canvas. The old rule squeezed it to a 64px strip of
     unlabelled text, which was unusable on a phone. */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: 264px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--sh-3); overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; }
  body.nav-open { overflow: hidden; }
  .nav-toggle { display: inline-flex; }
  .nav-item { min-height: var(--tap); }

  .content { padding: 16px 14px 32px; }
  .topbar { padding: 8px 14px; }
  .admin-foot { padding: 12px 14px; }
  h1 { font-size: 1.24rem; }

  .stat-grid, .form-grid, .form-2col { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .toolbar { padding: 10px; }
  .toolbar-sep { display: none; }
  .chat-window { height: calc(100dvh - 190px); border-radius: var(--r); }
  .chat-bubble { max-width: 85%; }
  .barlbl { width: 108px; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn, .page-head-actions .btn-primary { flex: 1; }
}

@media (max-width: 560px) {
  .who .role { display: none; }
  .cards, .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .card, .metric { padding: 13px 14px; }
  .card-num, .metric-num { font-size: 1.4rem; }
  .form-card { padding: 16px 14px; }
  .panel { padding: 15px 14px; }
  .form-actions .btn, .form-actions .btn-primary { flex: 1; }
}

/* ---- 20. Motion + print -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

@media print {
  .sidebar, .topbar, .toolbar, .page-head-actions, .form-actions,
  .row-actions, .chat-compose, .admin-foot, .scrim { display: none !important; }
  body { background: #fff; }
  .panel, .table-card, .data-table { border-color: #ccc; box-shadow: none; }
  .content { padding: 0; }
  a { color: inherit; text-decoration: none; }
}

