/* ============================================================
   Dominus OrderFlow — Professional UI
   Enterprise-grade PO Management System
   ============================================================ */

/* ---- Tokens ---- */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;

  --primary: #2563eb; --primary-hover: #1d4ed8; --primary-light: #dbeafe; --primary-fg: #fff;
  --success: #059669; --success-light: #d1fae5; --success-fg: #065f46;
  --warning: #d97706; --warning-light: #fef3c7; --warning-fg: #92400e;
  --danger: #dc2626;  --danger-light: #fee2e2;  --danger-fg: #991b1b;
  --info: #0284c7;    --info-light: #e0f2fe;    --info-fg: #075985;

  --g50: #f8fafc; --g100: #f1f5f9; --g200: #e2e8f0; --g300: #cbd5e1;
  --g400: #94a3b8; --g500: #64748b; --g600: #475569; --g700: #334155;
  --g800: #1e293b; --g900: #0f172a;

  --bg: #f1f5f9; --surface: #fff; --border: #e2e8f0;
  --text: #1e293b; --text-secondary: #64748b; --text-muted: #94a3b8;

  --sidebar-w: 252px; --topbar-h: 60px;
  --radius-sm: 6px; --radius: 8px; --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --transition: 150ms ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--g100); padding: 1px 5px; border-radius: 4px; color: var(--g700); }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w); background: var(--g900); color: var(--g400);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100; transition: transform .2s;
}
.sidebar-header { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 36px; height: 36px; border-radius: var(--radius);
  background: var(--primary); color: white; display: flex;
  align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: -0.5px;
}
.brand-name { font-size: 16px; font-weight: 700; color: #fff; display: block; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--g500); text-transform: uppercase; letter-spacing: 1.5px; font-weight: 500; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: var(--radius-sm); color: var(--g400);
  font-size: 13.5px; font-weight: 500; transition: all var(--transition);
  margin-bottom: 2px;
}
.sidebar-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.sidebar-link.active {
  color: #fff; background: rgba(37,99,235,.15);
  box-shadow: inset 3px 0 0 var(--primary);
}
.sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .6; }
.sidebar-link.active .sidebar-icon { opacity: 1; }

.sidebar-footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: white; display: flex;
  align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; color: var(--g200); font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--g500); display: block; }
.sidebar-logout { color: var(--g500); padding: 4px; border-radius: 4px; transition: color var(--transition); }
.sidebar-logout:hover { color: var(--danger); }

/* ---- Mobile header ---- */
.mobile-header { display: none; }

/* ---- Main content ---- */
.main-content {
  margin-left: var(--sidebar-w); flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
}
.top-bar {
  height: var(--topbar-h); padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 18px; font-weight: 700; color: var(--text); }
.top-actions { display: flex; gap: 8px; align-items: center; }

.content-area { padding: 24px 28px; flex: 1; }
.flash-container { padding: 0 28px; }
.flash-msg {
  padding: 10px 16px; border-radius: var(--radius-sm); margin: 8px 0;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13.5px; font-weight: 500;
}
.flash-msg.flash-success { background: var(--success-light); color: var(--success-fg); }
.flash-msg.flash-error   { background: var(--danger-light);  color: var(--danger-fg); }
.flash-msg.flash-warning { background: var(--warning-light); color: var(--warning-fg); }
.flash-msg.flash-info    { background: var(--info-light);    color: var(--info-fg); }
.flash-close { background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; opacity: .5; padding: 0 4px; }
.flash-close:hover { opacity: 1; }

/* ============================================================
   PANELS (Cards)
   ============================================================ */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  padding: 14px 20px; display: flex; align-items: center;
  justify-content: space-between; min-height: 48px;
}
.panel-title { font-size: 14px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.panel-body { padding: 16px 20px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; font-family: var(--font);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition); text-decoration: none;
  white-space: nowrap; line-height: 1.4;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-fg); }
.btn-ghost { background: transparent; color: var(--g600); border-color: var(--border); }
.btn-ghost:hover { background: var(--g50); border-color: var(--g300); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ============================================================
   TABLES
   ============================================================ */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
  padding: 10px 14px; text-align: left; font-size: 11px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--g500); background: var(--g50); border-bottom: 2px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.summary-table { border-collapse: separate; border-spacing: 0; }
.data-table thead th.text-right { text-align: right; }
.data-table tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--g100);
  font-size: 13.5px; vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--g50); }
.data-table tbody tr.row-inactive { opacity: .5; }
.data-table tbody tr.row-highlight { background: var(--warning-light); }
.data-table tfoot td { padding: 10px 14px; border-top: 2px solid var(--border); font-weight: 600; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.cell-sub { color: var(--g500); font-size: 12.5px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-layout { max-width: 720px; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 12.5px; font-weight: 600; color: var(--g600);
  margin-bottom: 4px; letter-spacing: .01em;
}
input[type="text"], input[type="email"], input[type="url"], input[type="password"],
input[type="number"], input[type="date"], input[type="tel"], select, textarea {
  width: 100%; padding: 8px 12px; font-size: 13.5px; font-family: var(--font);
  border: 1px solid var(--g300); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; min-height: 60px; }
.form-help { font-size: 12px; color: var(--g500); margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-actions { display: flex; gap: 8px; padding-top: 16px; }
.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer; color: var(--g700);
}
.filter-bar { margin-bottom: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-input {
  padding: 7px 12px; font-size: 13px; border: 1px solid var(--g300);
  border-radius: var(--radius-sm); background: var(--surface); font-family: var(--font);
}
.filter-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.filter-select {
  padding: 7px 10px; font-size: 13px; border: 1px solid var(--g300);
  border-radius: var(--radius-sm); background: var(--surface); font-family: var(--font);
}

/* ============================================================
   DETAIL LAYOUT
   ============================================================ */
.detail-layout { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px 20px; }
.detail-field { margin-bottom: 6px; }
.detail-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--g500); display: block; }
.detail-value { font-size: 13.5px; color: var(--text); }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  font-size: 11.5px; font-weight: 600; border-radius: 10px;
  background: var(--g100); color: var(--g600);
}
.badge-success { background: var(--success-light); color: var(--success-fg); }
.badge-warning { background: var(--warning-light); color: var(--warning-fg); }
.badge-danger  { background: var(--danger-light);  color: var(--danger-fg); }
.badge-info    { background: var(--info-light);    color: var(--info-fg); }
.badge-muted   { background: var(--g100); color: var(--g500); }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  font-size: 11.5px; font-weight: 600; border-radius: 10px;
  background: var(--g100); color: var(--g600);
}
.status-badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.status-pending        { background: #fef9c3; color: #854d0e; }
.status-pending::before { background: #eab308; }
.status-in_production  { background: #dbeafe; color: #1e40af; }
.status-in_production::before { background: #3b82f6; }
.status-ready_to_ship  { background: #cffafe; color: #0e7490; }
.status-ready_to_ship::before { background: #06b6d4; }
.status-partial_ship   { background: #fef3c7; color: #92400e; }
.status-partial_ship::before { background: #f59e0b; }
.status-shipped        { background: #d1fae5; color: #065f46; }
.status-shipped::before { background: #10b981; }
.status-completed      { background: #f0fdf4; color: #166534; }
.status-completed::before { background: #22c55e; }
.status-cancelled      { background: #fee2e2; color: #991b1b; }
.status-cancelled::before { background: #ef4444; }

/* ============================================================
   STAT CARDS (Dashboard)
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm); border-top: 3px solid var(--g300);
}
.stat-card.stat-blue   { border-top-color: var(--primary); }
.stat-card.stat-green  { border-top-color: var(--success); }
.stat-card.stat-purple { border-top-color: #8b5cf6; }
.stat-card.stat-orange { border-top-color: #f97316; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--g500); text-transform: uppercase; letter-spacing: .05em; margin-top: 4px; }

/* ============================================================
   ACCORDION
   ============================================================ */
.form-accordion .panel { margin-bottom: 4px; }
.acc-header {
  cursor: pointer; user-select: none; transition: background var(--transition);
}
.acc-header:hover { background: var(--g50); }
.acc-toggle {
  display: inline-block; width: 18px; text-align: center;
  font-size: 11px; color: var(--g400); transition: transform .2s; margin-right: 6px;
}
.acc-toggle.open { transform: rotate(90deg); }
.acc-body { display: none; border-top: 1px solid var(--border); }
.acc-body.open { display: block; }
.acc-hint {
  font-size: 11.5px; padding: 2px 8px; border-radius: 10px; margin-left: 8px;
  background: var(--g100); color: var(--g500); font-weight: 500;
}

/* ============================================================
   RESULTS META
   ============================================================ */
.results-meta {
  padding: 6px 0; font-size: 12.5px; color: var(--g500); font-weight: 500;
  display: flex; align-items: center; gap: 12px;
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(135deg, var(--g900) 0%, #1a237e 100%);
}
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 36px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-brand { font-size: 24px; font-weight: 700; color: var(--text); }
.login-subtitle { font-size: 13px; color: var(--g500); margin-top: 4px; }
.login-form .form-group { margin-bottom: 16px; }
.login-form .btn { width: 100%; padding: 10px; font-size: 14px; }
.login-footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--g400); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.3); }
  .mobile-header {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; background: var(--g900); color: white;
    position: sticky; top: 0; z-index: 90;
  }
  .mobile-toggle { background: none; border: none; color: white; cursor: pointer; padding: 4px; }
  .mobile-brand { font-weight: 700; font-size: 16px; }
  .main-content { margin-left: 0; }
  .top-bar { display: none; }
  .content-area { padding: 16px; }
  .flash-container { padding: 0 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-form { flex-direction: column; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .data-table { font-size: 12.5px; }
  .data-table thead th, .data-table tbody td { padding: 8px 10px; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .sidebar, .mobile-header, .top-bar, .top-actions, .flash-container { display: none; }
  .main-content { margin-left: 0; }
  .panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
