/* ═══════════════════════════════════════════════════════════════════
   I AM CORE — Unified Design System  v2
   Single source of truth for tokens, components & utilities
   ═══════════════════════════════════════════════════════════════════ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ── Design Tokens ── */
:root {
  /* Brand */
  --brand:          #E07A5F;
  --brand-hover:    #C9613F;
  --brand-10:       rgba(224,122,95,0.10);
  --brand-20:       rgba(224,122,95,0.20);

  /* Green / compliance */
  --green:          #2D5016;
  --green-hover:    #1E3A0F;
  --green-light:    #EBF5EF;
  --green-10:       rgba(45,80,22,0.10);

  /* Chrome (sidebar / topbar) */
  --chrome:         #141410;
  --chrome-border:  rgba(255,255,255,0.06);

  /* Surfaces */
  --page-bg:        #F5F4F0;
  --surface:        #FFFFFF;
  --surface-2:      #FAFAF8;
  --surface-3:      #F5F4F0;

  /* Borders */
  --border:         #E8E5E0;
  --border-light:   #F0EDE8;
  --border-dark:    #C8C4BB;

  /* Text */
  --text-1:         #1A1A18;
  --text-2:         #3D3D3A;
  --text-3:         #6B6860;
  --text-4:         #9B9890;
  --text-5:         #C0BDB8;

  /* Status */
  --s-green:        #2D7D4A;
  --s-green-bg:     #EBF5EF;
  --s-amber:        #B45309;
  --s-amber-bg:     #FEF3C7;
  --s-red:          #B91C1C;
  --s-red-bg:       #FEF2F2;
  --s-blue:         #1D4ED8;
  --s-blue-bg:      #EFF6FF;
  --s-grey:         #6B6860;
  --s-grey-bg:      #F0EDE8;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:     0 2px 8px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-lg:  0 8px 28px rgba(0,0,0,0.11), 0 2px 8px rgba(0,0,0,0.06);
  --shadow-xl:  0 16px 48px rgba(0,0,0,0.14), 0 4px 14px rgba(0,0,0,0.08);
  --shadow-brand: 0 4px 16px rgba(224,122,95,0.28);

  /* Radius */
  --r-xs:   4px;
  --r-sm:   7px;
  --r:      10px;
  --r-lg:   14px;
  --r-xl:   18px;
  --r-2xl:  24px;
  --r-full: 9999px;

  /* Transitions */
  --t-fast: 110ms ease;
  --t:      175ms ease;
  --t-slow: 280ms ease;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--page-bg);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--brand); text-decoration: none; }
a:hover { opacity: .82; }
img { max-width: 100%; }

/* ── Typography helpers ── */
.label-caps {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-4);
}
.text-muted    { color: var(--text-4) !important; }
.text-secondary{ color: var(--text-3) !important; }
.text-brand    { color: var(--brand)  !important; }
.text-green    { color: var(--green)  !important; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

/* ═══ TOPBAR (dark chrome – all standalone pages) ═══ */
.topbar {
  background: var(--chrome);
  height: 54px;
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--chrome-border);
}
.topbar-logo {
  font-size: 15px;
  font-weight: 800;
  color: var(--brand);
  letter-spacing: -0.025em;
  white-space: nowrap;
  text-decoration: none;
}
.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.92);
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-size: 11.5px;
  color: rgba(255,255,255,0.42);
  margin-top: 1px;
}
.topbar-sep {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.10);
  flex-shrink: 0;
}
.topbar-spacer { flex: 1; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.48);
  text-decoration: none;
  transition: color var(--t-fast);
}
.back-link:hover { color: rgba(255,255,255,0.85); text-decoration: none; opacity: 1; }
.back-link svg { flex-shrink: 0; }

/* ═══ BUTTONS ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  line-height: 1;
  white-space: nowrap;
  transition:
    background var(--t-fast),
    transform   var(--t-fast),
    box-shadow  var(--t-fast),
    opacity     var(--t-fast);
  text-decoration: none !important;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px) !important; }
.btn:disabled { opacity: 0.42; cursor: not-allowed; transform: none !important; pointer-events: none; }

.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-brand);
}

.btn-green {
  background: var(--green);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-green:hover:not(:disabled) {
  background: var(--green-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(45,80,22,0.28);
}

.btn-outline {
  background: var(--surface);
  color: var(--text-1);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-outline:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--border-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-ghost {
  background: transparent;
  color: var(--text-3);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text-1);
  border-color: var(--border-dark);
}

.btn-danger {
  background: var(--s-red-bg);
  color: var(--s-red);
  border: 1.5px solid #FECACA;
}
.btn-danger:hover:not(:disabled) { background: #FEE2E2; transform: translateY(-1px); }

.btn-dark {
  background: var(--chrome);
  color: rgba(255,255,255,0.88);
  box-shadow: var(--shadow-sm);
}
.btn-dark:hover:not(:disabled) {
  background: #232320;
  transform: translateY(-1px);
}

/* Sizes */
.btn-xs  { font-size: 11px;  padding: 4px 10px;  border-radius: var(--r-xs); gap: 4px; }
.btn-sm  { font-size: 12px;  padding: 6px 13px;  border-radius: var(--r-sm); }
.btn-lg  { font-size: 14px;  padding: 11px 22px; border-radius: var(--r); }
.btn-xl  { font-size: 15px;  padding: 14px 28px; border-radius: var(--r-lg); }
.btn-icon{ padding: 7px;     border-radius: var(--r-sm); }
.btn-icon.btn-sm { padding: 5px; }

/* ═══ CARDS ═══ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 15px 18px 13px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.01em;
  flex: 1;
}
.card-body    { padding: 16px 18px; }
.card-footer  {
  padding: 11px 18px;
  border-top: 1px solid var(--border-light);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ═══ INPUTS & FORMS ═══ */
.form-group { margin-bottom: 16px; }
.form-group label,
label.form-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 5px;
  letter-spacing: .01em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
input[type="tel"],
input[type="url"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-1);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  -webkit-appearance: none;
  appearance: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-10);
}
input::placeholder,
textarea::placeholder { color: var(--text-5); }
select { cursor: pointer; 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='%239B9890' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px; }
textarea { resize: vertical; min-height: 82px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ═══ BADGES / STATUS ═══ */
.badge,
.compliance-dot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: var(--r-full);
  white-space: nowrap;
  line-height: 1.4;
}

/* colour variants — both .badge-X and .status-X names honoured */
.status-green, .badge-green { background: var(--s-green-bg); color: var(--s-green); }
.status-amber, .badge-amber { background: var(--s-amber-bg); color: var(--s-amber); }
.status-red,   .badge-red   { background: var(--s-red-bg);   color: var(--s-red);   }
.status-blue,  .badge-blue  { background: var(--s-blue-bg);  color: var(--s-blue);  }
.status-grey,  .status-gray,
.badge-grey,   .badge-gray  { background: var(--s-grey-bg);  color: var(--s-grey);  }
.badge-brand                { background: var(--brand-10);   color: var(--brand-hover); }
.badge-green-solid          { background: var(--green);      color: #fff; }
.badge-brand-solid          { background: var(--brand);      color: #fff; }

/* ═══ TABLES ═══ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
table.core-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.core-table thead th {
  background: var(--chrome);
  color: rgba(255,255,255,0.78);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-right: 1px solid var(--chrome-border);
}
table.core-table thead th:last-child { border-right: none; }
table.core-table tbody tr { border-bottom: 1px solid var(--border-light); transition: background var(--t-fast); }
table.core-table tbody tr:last-child { border-bottom: none; }
table.core-table tbody tr:nth-child(even) { background: var(--surface-2); }
table.core-table tbody tr:hover { background: #F0F8EC; }
table.core-table tbody td {
  padding: 9px 12px;
  vertical-align: middle;
  color: var(--text-2);
  border-right: 1px solid var(--border-light);
  font-size: 13px;
}
table.core-table tbody td:last-child { border-right: none; }

/* ═══ MODALS ═══ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,8,0.50);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: coreModalIn 190ms cubic-bezier(.2,.8,.4,1) forwards;
}
@keyframes coreModalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1)  translateY(0); }
}
.modal-header {
  padding: 18px 20px 15px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
}
.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.015em;
}
.modal-close {
  width: 28px; height: 28px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--s-red-bg); color: var(--s-red); }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 13px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--surface-2);
}

/* ═══ PAGE CHROME ═══ */
.page-wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 21px;
  font-weight: 800;
  color: var(--text-1);
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.page-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
  font-weight: 400;
}
.section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-4);
  margin-bottom: 10px;
}

/* ═══ TOOLBAR / CONTROL BAR ═══ */
.control-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.control-bar input[type="date"],
.control-bar input[type="search"],
.control-bar input[type="text"] {
  width: auto;
  font-size: 12.5px;
  padding: 7px 11px;
}

/* ═══ EMPTY STATE ═══ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  color: var(--text-4);
  text-align: center;
  gap: 8px;
}
.empty-state .es-icon { font-size: 32px; opacity: .6; }
.empty-state .es-title { font-size: 14px; font-weight: 600; color: var(--text-3); }
.empty-state .es-sub   { font-size: 13px; }

/* ═══ TOASTS ═══ */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1E1E1A;
  color: rgba(255,255,255,0.92);
  border-radius: var(--r-lg);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  min-width: 220px;
  max-width: 360px;
  border: 1px solid rgba(255,255,255,0.06);
  animation: toastSlide 200ms cubic-bezier(.2,.8,.4,1) forwards;
}
@keyframes toastSlide {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.toast.success::before { content:'✓'; font-weight:800; color:#4ade80; font-size:14px; }
.toast.error::before   { content:'✕'; font-weight:800; color:#f87171; font-size:14px; }
.toast.info::before    { content:'ℹ'; font-weight:800; color:#60a5fa; font-size:14px; }
.toast.warning::before { content:'!'; font-weight:800; color:#fbbf24; font-size:14px; }

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar            { width: 5px; height: 5px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: var(--border-dark); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover{ background: var(--text-4); }

/* ═══ UTILITY CLASSES ═══ */
.flex            { display: flex; }
.flex-col        { display: flex; flex-direction: column; }
.items-center    { align-items: center; }
.items-start     { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.justify-center  { justify-content: center; }
.flex-1          { flex: 1; }
.flex-wrap       { flex-wrap: wrap; }
.gap-1   { gap:  4px; }
.gap-2   { gap:  8px; }
.gap-3   { gap: 12px; }
.gap-4   { gap: 16px; }
.gap-5   { gap: 20px; }
.gap-6   { gap: 24px; }
.mt-1    { margin-top:  4px; }  .mt-2 { margin-top: 8px; }
.mt-3    { margin-top: 12px; }  .mt-4 { margin-top: 16px; }
.mt-6    { margin-top: 24px; }
.mb-2    { margin-bottom:  8px; } .mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.p-4     { padding: 16px; }
.p-5     { padding: 20px; }
.truncate{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full  { width: 100%; }
.hidden  { display: none !important; }
.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; }
.rounded-full { border-radius: var(--r-full) !important; }

/* ═══ DIVIDERS ═══ */
hr, .divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 16px 0;
}

/* ═══ CONFIRM DIALOG (shared) ═══ */
#confirmDialog {
  position: fixed; inset: 0;
  background: rgba(10,10,8,0.52);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#confirmDialog.open { display: flex; }
#confirmDialog .confirm-box {
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  padding: 28px 28px 22px;
  max-width: 380px;
  width: 100%;
  margin: 20px;
  animation: coreModalIn 190ms cubic-bezier(.2,.8,.4,1) forwards;
}
#confirmDialog .confirm-msg {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 20px;
  white-space: pre-line;
}
#confirmDialog .confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr !important; }
  .page-wrap { padding: 16px 14px 36px; }
  .modal { border-radius: var(--r-lg); margin: 10px; max-height: 95vh; }
  .btn-lg { font-size: 13px; padding: 10px 18px; }
  .page-title { font-size: 18px; }
}

/* ═══ PRINT ═══ */
@media print {
  .topbar, .control-bar, .btn, .modal-overlay, #toastContainer { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .card, .table-wrap { box-shadow: none; border: 1px solid #ccc; }
}
