/* ============================================================
   CHW JCC Management Portal — Design System
   Theme: Compassionate Precision
   ============================================================ */

/* ---- Font: Plus Jakarta Sans (local, variable) ----------- */
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/pjs-latin.52d04440a9fa.woff2") format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Plus Jakarta Sans';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/pjs-latin-ext.5ffe46eeb00d.woff2") format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

/* ---- CSS Variables --------------------------------------- */
:root {
  --color-navy:          #001d3e;
  --color-navy-mid:      #003263;
  --color-navy-light:    #204779;
  --color-teal:          #006a6a;
  --color-teal-bright:   #33cccc;
  --color-teal-dim:      #004f50;
  --color-teal-surface:  #e0f7f7;
  --color-magenta:       #ea005e;
  --color-magenta-bg:    #fff0f5;
  --color-lime:          #99cc33;
  --color-lime-bg:       #f4fae8;
  --color-yellow:        #ffcc33;
  --color-yellow-bg:     #fffbe6;
  --color-error:         #ba1a1a;
  --color-error-bg:      #ffdad6;
  --color-bg:            #f8fafc;
  --color-surface:       #ffffff;
  --color-surface-low:   #f5f3f3;
  --color-surface-mid:   #efeded;
  --color-surface-high:  #e4e2e2;
  --color-border:        #c3c6d0;
  --color-border-light:  #e9e8e7;
  --color-text:          #1b1c1c;
  --color-text-muted:    #43474f;
  --color-text-faint:    #737780;

  --font: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;

  --sp-1: 8px;  --sp-2: 16px; --sp-3: 24px;
  --sp-4: 32px; --sp-5: 40px; --sp-6: 48px;

  --r-sm: 4px; --r: 8px; --r-md: 12px;
  --r-lg: 16px; --r-xl: 24px; --r-pill: 9999px;

  --shadow-card:   0 1px 3px rgba(0,29,62,0.06), 0 4px 16px rgba(0,29,62,0.04);
  --shadow-raised: 0 4px 20px rgba(0,29,62,0.10);
  --shadow-nav:    2px 0 16px rgba(0,29,62,0.12);

  --sidebar-width: 248px;
  --topbar-height: 64px;
}

/* ---- Reset ----------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--color-teal); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }

/* ---- App Shell ------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

/* Unauthenticated pages (login etc) — no sidebar offset */
.body-unauth .main-area { margin-left: 0; }
.body-unauth .page-content { padding: 0; }

/* ---- Sidebar --------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--color-navy);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: var(--shadow-nav);
  overflow-y: auto;
}
.sidebar-brand {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-name {
  font-size: 17px; font-weight: 700; color: #fff; line-height: 1.3;
}
.sidebar-brand-sub {
  font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.06em; text-transform: uppercase; margin-top: 3px;
}
.sidebar-nav {
  flex: 1; padding: var(--sp-2) var(--sp-1);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-section-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  padding: var(--sp-2) var(--sp-2) 4px;
}
.sidebar-link {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px var(--sp-2); border-radius: var(--r);
  color: rgba(255,255,255,0.65);
  font-size: 14px; font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,0.12); color: #fff; }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.75; }
.sidebar-link.active svg, .sidebar-link:hover svg { opacity: 1; }

.sidebar-bottom {
  padding: var(--sp-2) var(--sp-1);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--sp-2);
}
.sidebar-avatar {
  width: 34px; height: 34px; border-radius: var(--r-pill);
  background: var(--color-teal-bright); color: var(--color-navy);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex-shrink: 0;
}
.sidebar-user-info { overflow: hidden; }
.sidebar-username {
  font-size: 13px; font-weight: 700;
  color: rgba(255,255,255,0.9);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-role { font-size: 11px; color: rgba(255,255,255,0.4); }

/* ---- Main Area ------------------------------------------- */
.main-area { margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---- Topbar ---------------------------------------------- */
.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  display: flex; align-items: center;
  padding: 0 var(--sp-4); gap: var(--sp-2);
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 700; color: var(--color-text); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-1); }

/* ---- Page Content ---------------------------------------- */
.page-content { padding: var(--sp-4); flex: 1; }
.page-header { margin-bottom: var(--sp-4); }
.page-title { font-size: 28px; font-weight: 700; color: var(--color-text); line-height: 1.2; }
.page-subtitle { font-size: 14px; color: var(--color-text-muted); margin-top: 4px; }

/* ---- Cards ----------------------------------------------- */
.card {
  background: var(--color-surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--color-border-light);
  overflow: hidden;
}
.card-header {
  padding: var(--sp-3) var(--sp-3) 0;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 16px; font-weight: 700; color: var(--color-text); }
.card-body { padding: var(--sp-3); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-2); margin-bottom: var(--sp-4);
}
.stat-card {
  background: var(--color-surface); border-radius: var(--r-lg);
  padding: var(--sp-3); border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-card);
}
.stat-label {
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-faint); margin-bottom: var(--sp-1);
}
.stat-value { font-size: 36px; font-weight: 700; color: var(--color-navy); line-height: 1; }
.stat-value span { font-size: 16px; font-weight: 500; color: var(--color-text-faint); }

/* ---- Buttons --------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 10px var(--sp-2); border-radius: var(--r);
  font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; border: none; line-height: 1;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:hover  { text-decoration: none; }
.btn-primary   { background: var(--color-navy); color: #fff; }
.btn-primary:hover { background: var(--color-navy-mid); color: #fff; }
.btn-secondary { background: transparent; color: var(--color-teal); border: 2px solid var(--color-teal); }
.btn-secondary:hover { background: var(--color-teal-surface); color: var(--color-teal); }
.btn-ghost  { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover  { background: var(--color-surface-mid); color: var(--color-text); }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:hover { background: #93000a; color: #fff; }
.btn-teal   { background: var(--color-teal); color: #fff; }
.btn-teal:hover { background: var(--color-teal-dim); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px var(--sp-3); font-size: 16px; border-radius: var(--r-md); }

/* ---- Badges / Pills -------------------------------------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap;
}
.badge-magenta { background: var(--color-magenta-bg); color: var(--color-magenta); }
.badge-yellow  { background: var(--color-yellow-bg);  color: #8a6000; }
.badge-teal    { background: var(--color-teal-surface); color: var(--color-teal-dim); }
.badge-lime    { background: var(--color-lime-bg);    color: #4a6600; }
.badge-navy    { background: rgba(0,29,62,0.08);      color: var(--color-navy); }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error); }
.badge-muted   { background: var(--color-surface-high); color: var(--color-text-faint); }

.priority-high   { border-left: 4px solid var(--color-magenta) !important; }
.priority-medium { border-left: 4px solid var(--color-yellow) !important; }
.priority-stable { border-left: 4px solid var(--color-teal-bright) !important; }

/* ---- Tables ---------------------------------------------- */
.table-container {
  overflow-x: auto; border-radius: var(--r-lg);
  border: 1px solid var(--color-border-light); box-shadow: var(--shadow-card);
}
table { width: 100%; border-collapse: collapse; background: var(--color-surface); font-size: 14px; }
thead th {
  padding: var(--sp-2); text-align: left;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--color-text-faint); background: var(--color-surface-low);
  border-bottom: 1px solid var(--color-border-light); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--color-border-light); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-low); }
tbody td { padding: var(--sp-2); color: var(--color-text); vertical-align: middle; }

/* ---- Forms ----------------------------------------------- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-2); }
.form-label { font-size: 14px; font-weight: 600; color: var(--color-text-muted); }
.form-hint  { font-size: 12px; color: var(--color-text-faint); }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input[type="search"],
input[type="number"], select, textarea {
  width: 100%;
  padding: 10px var(--sp-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--r);
  background: var(--color-surface-low);
  font-family: var(--font); font-size: 14px; font-weight: 400;
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none; appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px rgba(0,106,106,0.12);
  background: var(--color-surface);
}
input::placeholder, textarea::placeholder { color: var(--color-text-faint); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23737780' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px; cursor: pointer;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
input[type="checkbox"] { width: 16px; height: 16px; border-radius: var(--r-sm); accent-color: var(--color-teal); cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.form-section {
  margin-bottom: var(--sp-4); padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--color-border-light);
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section-title {
  font-size: 15px; font-weight: 700; color: var(--color-navy);
  margin-bottom: var(--sp-3);
  display: flex; align-items: center; gap: var(--sp-1);
}
.form-section-title::before {
  content: ''; display: block; width: 4px; height: 18px;
  background: var(--color-teal); border-radius: var(--r-sm);
}

.errorlist { list-style: none; padding: 0; }
.errorlist li { font-size: 12px; color: var(--color-error); margin-top: 4px; }

/* ---- Messages -------------------------------------------- */
.messages { list-style: none; margin-bottom: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-1); }
.messages li { padding: 12px var(--sp-2); border-radius: var(--r); font-size: 14px; font-weight: 500; }
.messages .success { background: var(--color-teal-surface); color: var(--color-teal-dim); border: 1px solid #99e6e6; }
.messages .error   { background: var(--color-error-bg);    color: var(--color-error);    border: 1px solid #ffb4ab; }
.messages .warning { background: var(--color-yellow-bg);   color: #8a6000;               border: 1px solid var(--color-yellow); }
.messages .info    { background: #e8f0fe;                  color: #1a56a0;               border: 1px solid #a8c4f5; }

/* ---- Search bar ------------------------------------------ */
.search-form { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.search-form input { flex: 1; border-radius: var(--r-pill); }
.search-form button { flex-shrink: 0; }

/* ---- HTMX row partials ----------------------------------- */
.row {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px var(--sp-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--r); margin-bottom: 4px; font-size: 14px;
}
.row .btn { margin-left: auto; }

#diagnosis-rows, #comorbidity-rows, #procedure-rows, #attendee-rows {
  display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--sp-2);
}

/* ---- Save status ----------------------------------------- */
#save-status { font-size: 12px; color: var(--color-teal); height: 20px; display: flex; align-items: center; }

/* ---- Login page ------------------------------------------ */
.login-shell {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; background: var(--color-bg); padding: var(--sp-3);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--color-surface);
  border-radius: var(--r-xl); box-shadow: var(--shadow-raised);
  padding: var(--sp-6) var(--sp-4); border: 1px solid var(--color-border-light);
}
.login-brand { text-align: center; margin-bottom: var(--sp-4); }
.login-brand-name { font-size: 22px; font-weight: 700; color: var(--color-navy); }
.login-brand-sub  { font-size: 13px; color: var(--color-text-faint); margin-top: 4px; }
.login-card h2 { font-size: 18px; font-weight: 700; color: var(--color-text); margin-bottom: var(--sp-3); }

/* ---- Responsive ------------------------------------------ */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(-248px); }
  .main-area { margin-left: 0; }
  .page-content { padding: var(--sp-2); }
  .topbar { padding: 0 var(--sp-2); }
  .form-row { grid-template-columns: 1fr; }
}

/* ---- Modal dialog ---------------------------------------- */
dialog {
  width: min(580px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  border: none;
  border-radius: var(--r-lg);
  box-shadow: 0 8px 40px rgba(0,29,62,0.22);
  padding: var(--sp-4);
  background: var(--color-surface);
}

dialog::backdrop {
  background: rgba(0, 29, 62, 0.45);
  backdrop-filter: blur(2px);
}
