:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0072ce;
  --primary-hover: #005ba6;
  --navy: #0f172a;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --blue-bg: #eff6ff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-alt); border-color: #cbd5e1; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: rgba(15, 23, 42, 0.06); color: var(--text); }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge-neutral { background: #e2e8f0; color: #334155; }
.badge-blue { background: var(--blue-bg); color: #1d4ed8; }
.badge-success { background: var(--success-bg); color: #047857; }
.badge-warn { background: var(--warn-bg); color: #b45309; }
.badge-danger { background: var(--danger-bg); color: #b91c1c; }
.badge-demo { background: #fef3c7; color: #92400e; }
.badge-live { background: #dcfce7; color: #166534; }

.role-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.pill-count {
  background: var(--warn);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  margin-left: 4px;
}

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}
.brand-header { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.brand-header h1 { margin: 0; font-size: 20px; }
.brand-header p { margin: 2px 0 0; font-size: 13px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; flex-shrink: 0;
}
.brand-logo.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 6px; }

.demo-box {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.demo-title { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-login-btn { flex-direction: column; align-items: flex-start; padding: 8px 10px; gap: 1px; }
.demo-login-btn span { font-size: 11px; color: var(--muted); font-weight: 500; }

/* Topbar */
.topbar {
  background: var(--navy);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.app-title { font-weight: 700; font-size: 15px; }
.nav-tabs { display: flex; gap: 4px; height: 100%; align-items: center; }
.nav-tab {
  background: transparent; border: none; color: #cbd5e1;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.nav-tab:hover { color: #fff; background: rgba(255,255,255,0.08); }
.nav-tab.active { color: #fff; background: var(--primary); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.topbar .btn-ghost { color: #cbd5e1; }
.topbar .btn-ghost:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* Layout */
.container { max-width: 1320px; margin: 0 auto; padding: 24px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.section-header h2 { margin: 0; font-size: 20px; }
.section-header p { margin: 2px 0 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-pinned { border-left: 4px solid var(--primary); }
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface-alt);
}
.card-header h3 { margin: 0; font-size: 15px; }
.card-title-row { display: flex; align-items: center; gap: 8px; }

/* Inputs & Forms */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: #334155; }
label.inline-label { flex-direction: row; align-items: center; gap: 8px; }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="search"], select, textarea {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 114, 206, 0.14);
}
.search-input { width: 300px; max-width: 100%; }
.search-bar-row { display: flex; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.search-bar-row input[type="search"] { flex: 1; }
.vendor-input { width: 180px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col-wide { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; margin-bottom: 16px; }
.admin-grid { display: grid; grid-template-columns: 1fr 1.1fr; gap: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.full-span { grid-column: 1 / -1; }
.inline-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-top: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.pad { padding: 18px; }
.pad-h { padding-left: 18px; padding-right: 18px; }
.actions-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions-row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th {
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.qty-input { width: 64px; padding: 4px 6px !important; }
.price-input { width: 92px; padding: 4px 6px !important; }

/* Modals */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: 10px;
  width: 100%; max-width: 640px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}
.modal-sm { max-width: 480px; }
.modal-xl { max-width: 1080px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  background: var(--surface-alt);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-close {
  background: none; border: none; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body-scroll { overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 8px; }

.title-badges-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Subcards inside Detail Modal */
.subcard {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: #fff;
}
.subcard-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.subcard-header h4 { margin: 0; font-size: 14px; }
.inline-search-add { display: flex; gap: 6px; }
.inline-search-add input { width: 260px; }

.quick-results {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
  max-height: 220px;
  overflow-y: auto;
}
.quick-result-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 8px; background: #fff; border-radius: 5px; margin-bottom: 6px;
  border: 1px solid var(--border);
}
.quick-result-row:last-child { margin-bottom: 0; }

.workflow-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.totals-list { display: flex; flex-direction: column; gap: 8px; }
.total-row { display: flex; justify-content: space-between; font-size: 13px; }
.total-row.grand {
  font-size: 16px; font-weight: 700;
  padding-top: 8px; border-top: 2px solid var(--border);
}
.divider { height: 1px; background: var(--border); margin: 14px 0; }

.signoff-panel { border-left: 4px solid var(--warn); background: #fffdf7; }
.signoff-panel.approved { border-left-color: var(--success); background: #f7fdf9; }

/* Comments */
.comments-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 220px; overflow-y: auto; margin-bottom: 12px;
}
.comment-item {
  padding: 8px 10px; border-radius: 6px; background: var(--surface-alt);
  border: 1px solid var(--border); font-size: 13px;
}
.comment-item.system { background: #f8fafc; border-style: dashed; color: var(--muted); font-size: 12px; }
.comment-meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.comment-form { display: flex; gap: 8px; }
.comment-form input { flex: 1; }

/* Alerts & Toast */
.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 10px; }
.alert-error { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: var(--warn-bg); color: #92400e; border: 1px solid #fde68a; }
.alert-success { background: var(--success-bg); color: #065f46; border: 1px solid #a7f3d0; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--navy); color: #fff;
  padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  z-index: 200; font-weight: 500; font-size: 13px;
}

@media (max-width: 900px) {
  .two-col-wide, .admin-grid, .two-col, .form-grid, .inline-form { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; }
}
