/* ── Variables ── */
:root {
  --bg: #f7f6f3;
  --bg-card: #ffffff;
  --bg-secondary: #f0efe9;
  --bg-hover: #eae9e2;
  --border: rgba(0,0,0,0.08);
  --border-md: rgba(0,0,0,0.13);
  --text-primary: #1a1a18;
  --text-secondary: #6b6b65;
  --text-muted: #9e9d97;
  --accent: #1a1a18;
  --accent-hover: #333330;
  --green: #1d9e75;
  --green-bg: #e1f5ee;
  --amber: #ba7517;
  --amber-bg: #faeeda;
  --red: #a32d2d;
  --red-bg: #fcebeb;
  --blue: #185fa5;
  --blue-bg: #e6f1fb;
  --purple: #534ab7;
  --purple-bg: #eeedfe;
  --teal: #0f6e56;
  --teal-bg: #e1f5ee;
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 32px; height: 32px;
  background: var(--text-primary);
  color: white;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
}
.brand-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-muted); }
.nav-group { padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-secondary); color: var(--text-primary); font-weight: 500; }
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-divider {
  padding: 10px 18px 4px;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
}
.sidebar-footer { margin-top: auto; padding: 12px 8px; border-top: 1px solid var(--border); }
.user-pill {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 2px;
}
.user-avatar {
  width: 30px; height: 30px;
  background: var(--bg-secondary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--text-muted); }
.logout-btn { color: var(--text-muted) !important; }

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1280px;
}

/* ── Page header ── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px;
}
.page-header h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 6px;
}
.back-link:hover { color: var(--text-primary); }
.page-header-left { display: flex; flex-direction: column; }
.header-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-md);
  cursor: pointer;
  transition: all 0.12s;
  background: var(--bg-card);
  color: var(--text-primary);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--text-primary); color: white; border-color: transparent; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-card); }
.btn-danger { background: var(--red); color: white; border-color: transparent; }
.btn-danger:hover { background: #8a2525; }
.btn-ghost-danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn-ghost-danger:hover { background: var(--red-bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--radius);
  border: none; background: transparent;
  color: var(--text-muted); cursor: pointer;
  transition: all 0.12s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: var(--red-bg); color: var(--red); }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 {
  display: flex; align-items: center; gap: 7px;
  font-size: 14px; font-weight: 500;
}
.card-header h3 i { font-size: 16px; color: var(--text-secondary); }
.card-body { padding: 16px 18px; }
.empty-state { font-size: 13px; color: var(--text-muted); text-align: center; padding: 12px 0; }

/* ── Stat cards (dashboard) ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-header { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 12px; }
.stat-header i { font-size: 15px; }
.stat-numbers { display: flex; gap: 20px; }
.stat-num span { display: block; font-size: 26px; font-weight: 600; letter-spacing: -0.03em; }
.stat-num small { font-size: 11px; color: var(--text-muted); }
.stat-num.warn span { color: var(--amber); }
.stat-num.muted span { color: var(--text-muted); }
.stat-teal { border-top: 3px solid var(--teal); }
.stat-purple { border-top: 3px solid var(--purple); }
.stat-amber { border-top: 3px solid var(--amber); }
.stat-blue { border-top: 3px solid var(--blue); }

/* ── Two col ── */
.two-col-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .two-col-grid { grid-template-columns: 1fr; } }

/* ── Alert row (dashboard) ── */
.alert-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.alert-row:last-child { border-bottom: none; }
.alert-name { font-weight: 500; flex: 1; }
.alert-name:hover { text-decoration: underline; }
.alert-area { font-size: 11px; color: var(--text-muted); }
.audit-row { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.audit-row:last-child { border-bottom: none; }
.audit-time { color: var(--text-muted); min-width: 110px; font-family: 'DM Mono', monospace; }
.audit-user { color: var(--text-secondary); font-weight: 500; min-width: 80px; }

/* ── Badges ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px; font-weight: 500;
  white-space: nowrap;
}
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-expiring { background: var(--amber-bg); color: var(--amber); }
.badge-expired { background: var(--bg-secondary); color: var(--text-secondary); }
.badge-former { background: var(--bg-secondary); color: var(--text-muted); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-info { background: var(--blue-bg); color: var(--blue); }
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-main { background: var(--blue-bg); color: var(--blue); }
.badge-type { background: var(--bg-secondary); color: var(--text-secondary); }
.badge-pkg { background: var(--purple-bg); color: var(--purple); }

/* ── Stats pills ── */
.stats-pills { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 20px; font-weight: 500; }
.pill-active { background: var(--green-bg); color: var(--green); }
.pill-warn { background: var(--amber-bg); color: var(--amber); }
.pill-muted { background: var(--bg-secondary); color: var(--text-secondary); }
.pill-former { background: var(--bg-secondary); color: var(--text-muted); }

/* ── Filter bar ── */
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-form { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-wrap i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 15px; pointer-events: none; z-index: 1; }
.search-wrap input { padding-left: 34px; width: 100%; position: relative; }

/* ── Table ── */
.table-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--bg-secondary); padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-secondary); letter-spacing: .03em; text-transform: uppercase; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); cursor: pointer; }
.cell-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; display: block; }
.row-expired td { color: var(--text-muted); }
.row-former td { color: var(--text-muted); opacity: 0.6; }
.row-arrow { color: var(--text-muted); width: 24px; }
.mono { font-family: 'DM Mono', monospace; }

/* ── Inputs ── */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 13px;
  transition: border 0.12s, box-shadow 0.12s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.field-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field-group label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Detail view ── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-col { display: flex; flex-direction: column; }
.detail-fields { display: flex; flex-direction: column; gap: 0; }
.detail-field {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 13px; gap: 10px;
}
.detail-field:last-child { border-bottom: none; }
.field-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; flex-shrink: 0; }
.field-val-wrap { text-align: right; }
.expired-reason .field-label { color: var(--amber); }

/* ── Pkg info bar ── */
.pkg-info-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--purple-bg); border: 1px solid rgba(83,74,183,0.2);
  border-radius: var(--radius); padding: 10px 14px;
  font-size: 13px; color: var(--purple); margin-bottom: 16px;
}

/* ── Benefits ── */
.benefit-block { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.benefit-block:last-child { border-bottom: none; margin-bottom: 0; }
.benefit-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 12px; }
.benefit-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.benefit-title i { font-size: 15px; color: var(--text-secondary); }
.benefit-meta { display: flex; align-items: center; gap: 10px; }
.benefit-counter { font-size: 13px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.benefit-counter span { color: var(--text-secondary); }
.alloc-input { width: 52px !important; padding: 3px 6px !important; font-size: 13px !important; text-align: center; border: 1px solid var(--border-md) !important; border-radius: 6px !important; background: var(--bg-secondary) !important; display: inline-block !important; }
.alloc-total { font-weight: 600; color: var(--text-primary); }
.benefit-bar { width: 80px; height: 6px; background: var(--bg-secondary); border-radius: 3px; overflow: hidden; }
.benefit-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.benefit-use-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.benefit-use-row:last-child { border-bottom: none; }
.benefit-use-row i { font-size: 14px; color: var(--text-muted); margin-top: 1px; flex-shrink: 0; }
.benefit-use-info { flex: 1; }
.benefit-use-detail { color: var(--text-muted); margin-top: 2px; }
.benefit-use-date { color: var(--text-muted); font-size: 11px; white-space: nowrap; }
.link-ext { color: var(--blue); margin-left: 4px; }

/* ── Contacts ── */
.contact-card {
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.contact-card:last-child { border-bottom: none; }
.contact-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.contact-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--blue-bg); color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.contact-name { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 5px; }
.contact-pos { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.contact-actions { margin-left: auto; display: flex; gap: 2px; }
.contact-fields { display: flex; flex-direction: column; gap: 4px; padding-left: 44px; }
.contact-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.contact-field i { font-size: 13px; }
.contact-field:hover { color: var(--text-primary); }

/* ── Notes ── */
.note-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-content { font-size: 13px; line-height: 1.6; margin-bottom: 6px; white-space: pre-wrap; }
.note-meta { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.note-meta i { font-size: 12px; }
.note-actions { margin-left: auto; display: flex; gap: 2px; }
.add-note-form { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; margin-top: 4px; border-top: 1px solid var(--border); }

/* ── Documents ── */
.doc-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.doc-item:last-child { border-bottom: none; }
.doc-item i { font-size: 18px; color: var(--text-muted); flex-shrink: 0; }
.doc-info { flex: 1; }
.doc-name { font-weight: 500; }
.doc-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.doc-actions { display: flex; gap: 2px; }

/* ── Forms ── */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.member-form { max-width: 900px; }
.form-sections { display: flex; flex-direction: column; gap: 24px; }
.form-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px 24px; }
.form-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.contact-form-block { padding: 14px 0; border-bottom: 1px solid var(--border); }
.contact-form-block:last-child { border-bottom: none; }
.contact-form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .04em; }

/* ── Package cards ── */
.pkg-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 12px; margin-bottom: 24px; }
.pkg-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; }
.pkg-card-header { margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.pkg-name { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.pkg-price-input { width: 100%; padding: 4px 8px; font-size: 12px; margin-top: 4px; }
.section-label { font-size: 11px; font-weight: 600; color: var(--text-muted); letter-spacing: .08em; text-transform: uppercase; margin: 20px 0 10px; }
.section-label:first-child { margin-top: 0; }

/* ── Checkbox group ── */
.checkbox-group { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; }

/* ── Login ── */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-brand { text-align: center; margin-bottom: 32px; }
.brand-logo-lg {
  width: 52px; height: 52px;
  background: var(--text-primary); color: white;
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
  margin: 0 auto 14px;
}
.login-brand h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-brand p { font-size: 13px; color: var(--text-muted); }
.login-form { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; box-shadow: var(--shadow); }
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(163,45,45,0.2); }

/* ── Misc ── */
.muted { color: var(--text-muted); }
.text-muted { color: var(--text-muted); font-size: 12px; }
.mb-1 { margin-bottom: 8px; }
.mt-1 { margin-top: 12px; }
.add-column-form { display: flex; gap: 8px; align-items: flex-end; }
.add-column-form input, .add-column-form select { width: auto; flex: 1; }
.columns-list-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.columns-list-item:last-child { border-bottom: none; }

/* Clickable email in list */
.cell-email { font-size: 11px; color: var(--blue); display: block; margin-top: 2px; }
.cell-email:hover { text-decoration: underline; }

/* Contact edit form */
.contact-edit-form .field-group { margin-bottom: 6px; }
.contact-edit-form label { font-size: 11px; }

/* Package inline edit */
.pkg-edit-field { display: flex; flex-direction: column; gap: 3px; }
.pkg-edit-field label { font-size: 10px; color: var(--purple); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.pkg-edit-field input { border: 1px solid rgba(83,74,183,0.3) !important; background: rgba(83,74,183,0.06) !important; border-radius: 5px; color: var(--text-primary); }
.pkg-benefits-str { font-size: 12px; color: var(--text-secondary); }

/* Sortable column headers */
th.sort-asc::after { content: ' ↑'; color: var(--text-muted); font-size: 10px; }
th.sort-desc::after { content: ' ↓'; color: var(--text-muted); font-size: 10px; }
thead th { user-select: none; }

/* Finance area header link */
.area-link-h3:hover { text-decoration: underline; text-decoration-color: var(--text-muted); }
