/* ===== PO TRACKING SYSTEM — STYLES =====
   Modern shadcn-style dashboard with status badges, sidebar, modals, toast */

:root {
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --primary: 221.2 83% 53%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --success: 142 72% 29%;
  --success-foreground: 210 40% 98%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --ring: 221.2 83% 53%;
  --radius: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --shadow-sm: 0 1px 2px hsl(222 47% 11% / .05);
  --shadow-md: 0 4px 12px hsl(222 47% 11% / .08);
  --shadow-lg: 0 8px 32px hsl(222 47% 11% / .1);
  --sidebar-width: 260px;
  --header-h: 60px;
  --tap: 44px;

  /* Status badge colors */
  --badge-info: #3b82f6;
  --badge-success: #16a34a;
  --badge-warning: #ca8a04;
  --badge-danger: #dc2626;
  --badge-neutral: #6b7280;
  --badge-primary: #7c3aed;
}

[data-theme="dark"] {
  --background: 222.2 84% 4.9%;
  --foreground: 210 40% 98%;
  --card: 222.2 84% 4.9%;
  --card-foreground: 210 40% 98%;
  --primary: 217.2 91% 60%;
  --primary-foreground: 222.2 47.4% 11.2%;
  --secondary: 217.2 32.6% 17.5%;
  --secondary-foreground: 210 40% 98%;
  --muted: 217.2 32.6% 17.5%;
  --muted-foreground: 215 20% 65%;
  --accent: 217.2 32.6% 17.5%;
  --border: 217.2 32.6% 17.5%;
  --shadow-md: 0 4px 12px hsl(0 0% 0% / .22);
  --shadow-lg: 0 8px 32px hsl(0 0% 0% / .28);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  line-height: 1.55;
  min-height: 100dvh;
  overflow-x: hidden;
}
button { cursor: pointer; font: inherit; }
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
img { max-width: 100%; display: block; }

/* ===== SKELETON ===== */
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton {
  background: linear-gradient(90deg, hsl(var(--muted)) 25%, hsl(var(--border)) 50%, hsl(var(--muted)) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
  height: 20px;
  margin-bottom: 8px;
}

/* ===== APP SHELL ===== */
.app-shell { display: flex; min-height: 100dvh; }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  z-index: 100;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-brand {
  padding: 16px 20px;
  border-bottom: 1px solid hsl(var(--border));
  display: flex; align-items: center; gap: 10px;
  min-height: var(--header-h);
}
.sidebar-brand .logo {
  width: 36px; height: 36px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 900; font-size: 1.2rem;
}
.sidebar-brand h1 { font-size: 1rem; font-weight: 800; line-height: 1.2; }
.sidebar-brand small { font-size: .7rem; color: hsl(var(--muted-foreground)); display: block; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: hsl(var(--muted-foreground));
  font-weight: 600; font-size: .88rem;
  border: none; background: none;
  width: 100%; text-align: left;
  transition: .15s;
}
.nav-item:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.nav-item.active { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.nav-item .nav-icon { font-size: 1.15rem; width: 24px; text-align: center; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: hsl(var(--muted-foreground)); padding: 16px 14px 6px; font-weight: 700; }
.sidebar-footer { padding: 12px 10px; border-top: 1px solid hsl(var(--border)); }

/* ===== MAIN CONTENT ===== */
.main-wrap { flex: 1; margin-left: 0; min-width: 0; display: flex; flex-direction: column; }
.main-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: hsl(var(--card)/.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid hsl(var(--border));
}
.main-header .page-title { font-size: 1.05rem; font-weight: 800; flex: 1; }
.header-search {
  display: none;
  position: relative; flex: 1; max-width: 320px;
}
.header-search input {
  width: 100%; height: 38px; padding: 0 12px 0 36px;
  border: 1px solid hsl(var(--border));
  border-radius: 999px;
  background: hsl(var(--muted));
  outline: none;
}
.header-search input:focus { border-color: hsl(var(--primary)); }
.header-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); opacity: .45; }
.btn-icon {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid hsl(var(--border)); border-radius: var(--radius);
  background: none; color: hsl(var(--muted-foreground));
  font-size: 1.1rem; position: relative;
}
.btn-icon:hover { background: hsl(var(--accent)); }
.badge-dot {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--badge-danger);
}
.main-content { flex: 1; padding: 20px 16px; max-width: 1400px; }

/* ===== PAGE HEADER ===== */
.page-header { margin-bottom: 20px; }
.page-header h2 { font-size: 1.35rem; font-weight: 800; margin-bottom: 4px; }
.page-header p { color: hsl(var(--muted-foreground)); font-size: .88rem; }

/* ===== METRIC GRID ===== */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.metric-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  padding: 16px;
}
.metric-card .m-label { font-size: .75rem; color: hsl(var(--muted-foreground)); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.metric-card .m-value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; }
.metric-card .m-change { font-size: .75rem; margin-top: 2px; color: hsl(var(--muted-foreground)); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px;
  border-radius: var(--radius); border: 1px solid transparent;
  font-weight: 600; font-size: .85rem;
  white-space: nowrap;
  transition: .15s;
}
.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { opacity: .9; }
.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); border-color: hsl(var(--border)); }
.btn-secondary:hover { background: hsl(var(--accent)); }
.btn-ghost { background: none; border-color: transparent; color: hsl(var(--muted-foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }
.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-sm { height: 30px; padding: 0 10px; font-size: .8rem; }
.btn-wide { width: 100%; }
.btn-icon-sm { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; font-size: .9rem; }

/* ===== STATUS BADGE ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: .72rem; font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap; line-height: 1.5;
}
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-neutral { background: #f3f4f6; color: #4b5563; }
.badge-primary { background: #ede9fe; color: #6d28d9; }

/* ===== CARDS ===== */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: .95rem; font-weight: 700; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; padding: 10px 12px; font-weight: 700; color: hsl(var(--muted-foreground)); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid hsl(var(--border)); }
td { padding: 10px 12px; border-bottom: 1px solid hsl(var(--border)); }
tr:hover td { background: hsl(var(--muted)); }

/* ===== FILTER BAR ===== */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filter-bar input, .filter-bar select {
  height: 38px; padding: 0 12px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  outline: none; min-width: 120px;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: hsl(var(--primary)); }
.filter-bar .search-input { flex: 1; min-width: 180px; max-width: 300px; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 360px;
}
.toast {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s ease-out;
  font-size: .88rem;
}
.toast.success { border-left: 4px solid var(--badge-success); }
.toast.error { border-left: 4px solid var(--badge-danger); }
.toast.info { border-left: 4px solid var(--badge-info); }
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  padding: 16px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: hsl(var(--card));
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 85dvh;
  overflow-y: auto;
  padding: 24px;
  transform: scale(.95); transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h2 { font-size: 1.15rem; font-weight: 800; }
.modal-close { width: 36px; height: 36px; border: none; background: none; font-size: 1.5rem; border-radius: var(--radius); display: grid; place-items: center; color: hsl(var(--muted-foreground)); }
.modal-close:hover { background: hsl(var(--accent)); }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid hsl(var(--border)); }

/* ===== FORM ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 4px; color: hsl(var(--foreground)); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  outline: none;
}
.form-group textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: hsl(var(--primary)); box-shadow: 0 0 0 2px hsl(var(--primary)/.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== KANBAN ===== */
.kanban-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; min-height: 400px; }
.kanban-col { min-width: 220px; max-width: 260px; flex-shrink: 0; }
.kanban-col-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; margin-bottom: 8px; font-weight: 700; font-size: .82rem; border-radius: var(--radius); background: hsl(var(--secondary)); }
.kanban-col-header .count { font-size: .75rem; color: hsl(var(--muted-foreground)); background: hsl(var(--muted)); padding: 2px 8px; border-radius: 999px; }
.kanban-cards { display: flex; flex-direction: column; gap: 8px; }
.kanban-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: .15s;
  position: relative;
}
.kanban-card:hover { box-shadow: var(--shadow-md); }
.kanban-card .kc-title { font-weight: 700; font-size: .88rem; margin-bottom: 4px; }
.kanban-card .kc-meta { font-size: .78rem; color: hsl(var(--muted-foreground)); }
.kanban-card .kc-amount { font-weight: 700; color: hsl(var(--foreground)); margin-top: 6px; }
.kanban-card .kc-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.kanban-card .kc-alert { position: absolute; top: 8px; right: 8px; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 48px 20px; color: hsl(var(--muted-foreground)); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.05rem; font-weight: 700; color: hsl(var(--foreground)); margin-bottom: 6px; }
.empty-state p { font-size: .88rem; }

/* ===== TIMELINE ===== */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 2px; background: hsl(var(--border)); }
.tl-item { position: relative; padding-bottom: 20px; }
.tl-item::before { content: ''; position: absolute; left: -22px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: hsl(var(--border)); border: 2px solid hsl(var(--card)); }
.tl-item.active::before { background: hsl(var(--primary)); }
.tl-item.future::before { background: hsl(var(--muted)); }
.tl-item .tl-title { font-weight: 700; font-size: .88rem; }
.tl-item .tl-meta { font-size: .78rem; color: hsl(var(--muted-foreground)); }
.tl-item .tl-desc { font-size: .82rem; color: hsl(var(--muted-foreground)); margin-top: 2px; }

/* ===== PDF INBOX TABLE ADAPTATIONS ===== */
.pdf-status { display: inline-flex; align-items: center; gap: 6px; }

/* ===== ALERT CENTER ===== */
.alert-card { display: flex; gap: 12px; padding: 14px; border: 1px solid hsl(var(--border)); border-radius: var(--radius); margin-bottom: 8px; background: hsl(var(--card)); align-items: flex-start; }
.alert-card .alert-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: .9rem; flex-shrink: 0; }
.alert-card .alert-body { flex: 1; }
.alert-card .alert-title { font-weight: 700; font-size: .88rem; }
.alert-card .alert-meta { font-size: .78rem; color: hsl(var(--muted-foreground)); margin-top: 2px; }
.alert-card .alert-actions { display: flex; gap: 6px; flex-shrink: 0; }
.alert-card.resolved { opacity: .5; }
.alert-card .badge-severity { font-size: .7rem; padding: 1px 8px; border-radius: 999px; font-weight: 700; display: inline-block; }

/* ===== SETTINGS ===== */
.settings-group { margin-bottom: 24px; }
.settings-group h3 { font-size: .9rem; font-weight: 700; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid hsl(var(--border)); }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.setting-row label { font-size: .88rem; font-weight: 600; }
.setting-row .setting-desc { font-size: .78rem; color: hsl(var(--muted-foreground)); }
.toggle {
  width: 44px; height: 24px; border-radius: 999px;
  background: hsl(var(--muted-foreground));
  border: none; position: relative; cursor: pointer;
  transition: .2s;
}
.toggle.active { background: hsl(var(--primary)); }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle.active::after { left: 22px; }

/* ===== CONFIRM DIALOG ===== */
.confirm-dialog .modal { max-width: 400px; text-align: center; }
.confirm-dialog .confirm-icon { font-size: 2.5rem; margin-bottom: 12px; }
.confirm-dialog h2 { font-size: 1.1rem; font-weight: 800; margin-bottom: 8px; }
.confirm-dialog p { font-size: .88rem; color: hsl(var(--muted-foreground)); margin-bottom: 20px; }

/* ===== SPLIT SCREEN (PO REVIEW) ===== */
.split-screen { display: grid; grid-template-columns: 1fr; gap: 16px; }
.pdf-preview-placeholder {
  background: hsl(var(--muted));
  border: 2px dashed hsl(var(--border));
  border-radius: var(--radius-lg);
  min-height: 300px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  color: hsl(var(--muted-foreground));
  font-size: .88rem;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
  .sidebar { transform: translateX(0); }
  .main-wrap { margin-left: var(--sidebar-width); }
  .header-search { display: block; }
  .split-screen { grid-template-columns: 1fr 1fr; }
  .metric-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .kanban-board { padding-bottom: 0; min-height: 500px; }
}
@media (min-width: 1024px) {
  .metric-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .main-content { padding: 24px; }
}

/* ===== MOBILE BOTTOM NAV (replaces sidebar on phone) ===== */
.mobile-nav {
  display: flex;
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 90;
  background: hsl(var(--card)/.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid hsl(var(--border));
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
  justify-content: space-around;
}
.mobile-nav a {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 8px;
  font-size: .65rem; font-weight: 700;
  color: hsl(var(--muted-foreground));
  border: none; background: none;
  min-width: 0;
}
.mobile-nav a .m-icon { font-size: 1.2rem; }
.mobile-nav a.active { color: hsl(var(--primary)); }
@media (min-width: 768px) { .mobile-nav { display: none; } }

/* ===== MISC ===== */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: hsl(var(--muted-foreground)); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== CONSOLE CHECKS ===== */
@media (max-width: 767px) {
  .hide-on-mobile { display: none !important; }
  .show-on-mobile { display: block !important; }
  .main-content { padding-bottom: 70px; }
}
@media (min-width: 768px) {
  .show-on-mobile { display: none !important; }
  .hide-on-mobile { display: block !important; }
}
.page-section:not(.active-section) { display: none; }
.page-section.active-section { display: block; }

/* ===== PRINT ===== */
@media print {
  .sidebar, .mobile-nav, .main-header, .toast-container, .modal-overlay { display: none !important; }
  .main-wrap { margin-left: 0; }
  body { background: #fff; }
}
