/* =====================================================================
   Purchasing Portal — Main Stylesheet
   Theme: Dark Navy / Professional Blue
   ===================================================================== */

/* === CSS Variables === */
:root {
  --navy:         #0d1b2a;
  --navy-mid:     #1b2f45;
  --dark-blue:    #1e3a5f;
  --mid-blue:     #1e4976;
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light:#3b82f6;
  --accent:       #60a5fa;
  --pale-blue:    #93c5fd;
  --lightest:     #dbeafe;
  --bg:           #f0f5fb;
  --bg-card:      #ffffff;
  --bg-card-2:    #f8faff;
  --text-primary: #1e293b;
  --text-muted:   #64748b;
  --text-light:   #ffffff;
  --border:       #e2e8f0;
  --border-focus: #2563eb;
  --success:      #10b981;
  --success-bg:   #d1fae5;
  --warning:      #f59e0b;
  --warning-bg:   #fef3c7;
  --danger:       #ef4444;
  --danger-bg:    #fee2e2;
  --info:         #3b82f6;
  --info-bg:      #dbeafe;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:       0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.07);
  --radius:       8px;
  --radius-lg:    12px;
  --header-h:     60px;
  --transition:   .18s ease;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* === Header === */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--navy);
  height: var(--header-h);
  box-shadow: 0 2px 10px rgba(0,0,0,.3);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Brand */
.site-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-light);
  text-decoration: none;
  flex-shrink: 0;
}
.site-brand:hover { text-decoration: none; opacity: .9; }
.brand-icon { font-size: 1.25rem; }
.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-light);
  white-space: nowrap;
}

/* Desktop Nav */
.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 24px;
  flex: 1;
}

.nav-link {
  color: rgba(255,255,255,.75);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(255,255,255,.1); color: var(--text-light); text-decoration: none; }
.nav-link.active { background: var(--primary); color: var(--text-light); }
.nav-admin { margin-left: auto; }

/* Hamburger */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.hamburger span {
  display: block;
  height: 2px;
  background: rgba(255,255,255,.85);
  border-radius: 2px;
  transition: all var(--transition);
}
.hamburger:hover { background: rgba(255,255,255,.1); }

/* User Menu */
.user-menu {
  position: relative;
  flex-shrink: 0;
}
.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: var(--text-light);
  padding: 6px 12px 6px 6px;
  border-radius: 24px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background var(--transition);
}
.user-btn:hover { background: rgba(255,255,255,.15); }
.user-avatar {
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}
.user-name { font-weight: 500; }
.chevron { transition: transform var(--transition); }
.user-btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity var(--transition), transform var(--transition);
  z-index: 200;
}
.user-dropdown.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.dropdown-header {
  padding: 12px 16px;
  background: var(--bg-card-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dropdown-header strong { font-size: 0.875rem; color: var(--text-primary); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.875rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background var(--transition);
}
.dropdown-item:hover { background: var(--bg-card-2); text-decoration: none; }
.logout-link { color: var(--danger); }
.logout-link:hover { background: var(--danger-bg); }

/* === Mobile Nav === */
.mobile-nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 150;
}
.mobile-nav-overlay.open { display: block; }

.mobile-nav {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--navy);
  z-index: 160;
  display: flex;
  flex-direction: column;
  padding: 0 0 24px;
  transform: translateX(-100%);
  transition: transform .25s ease;
  overflow-y: auto;
}
.mobile-nav.open { transform: translateX(0); }

.mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 8px;
}
.mobile-nav-header .brand-name { color: var(--text-light); }
.mobile-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.mobile-close:hover { background: rgba(255,255,255,.1); color: var(--text-light); }

.mobile-nav-link {
  display: block;
  padding: 12px 20px;
  color: rgba(255,255,255,.8);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}
.mobile-nav-link:hover { background: rgba(255,255,255,.07); color: var(--text-light); border-left-color: var(--primary); text-decoration: none; }

/* === Page Layout === */
.page-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.page-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
}
.page-header .subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
}
.card-body { padding: 20px; }

/* === Stat Cards (Dashboard) === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}
.stat-card.total::before  { background: var(--mid-blue); }
.stat-card.received::before { background: var(--warning); }
.stat-card.progress::before { background: var(--primary); }
.stat-card.finished::before { background: var(--success); }

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-number {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--navy);
}
.stat-bar-wrap {
  margin-top: 14px;
  background: var(--bg);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}
.stat-bar {
  height: 100%;
  border-radius: 4px;
  transition: width .6s ease;
}
.stat-card.received .stat-bar { background: var(--warning); }
.stat-card.progress  .stat-bar { background: var(--primary); }
.stat-card.finished  .stat-bar { background: var(--success); }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary   { background: var(--primary);   color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary { background: var(--bg-card); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-card-2); border-color: #c0cad8; }

.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #0ea271; }

.btn-danger    { background: var(--danger);  color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }

.btn-warning   { background: var(--warning); color: #fff; border-color: var(--warning); }

.btn-sm  { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg  { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* === Forms === */
.form-section {
  max-width: 800px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-group {
  margin-bottom: 16px;
}
.form-group.full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 5px;
}
label .required { color: var(--danger); margin-left: 2px; }

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=url],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { resize: vertical; min-height: 100px; }
select { cursor: pointer; }

.form-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 0.78rem; color: var(--danger); margin-top: 4px; }

/* File Input */
.file-input-wrap {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.file-input-wrap:hover { border-color: var(--primary); background: var(--lightest); }
.file-input-wrap input[type=file] { display: none; }
.file-input-label { color: var(--text-muted); font-size: 0.875rem; cursor: pointer; }
.file-input-label strong { color: var(--primary); }

/* === Tables === */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
}
thead tr {
  background: var(--dark-blue);
  color: var(--text-light);
}
thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { background: var(--mid-blue); }
thead th.sorted-asc::after  { content: ' ▲'; }
thead th.sorted-desc::after { content: ' ▼'; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:hover { background: var(--lightest); }
tbody tr:last-child { border-bottom: none; }
tbody td {
  padding: 12px 16px;
  font-size: 0.875rem;
  vertical-align: middle;
}
.td-actions { white-space: nowrap; }

/* Empty state */
.table-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.table-empty .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-received   { background: var(--warning-bg); color: #92400e; }
.badge-progress   { background: var(--info-bg);    color: #1e40af; }
.badge-finished   { background: var(--success-bg); color: #065f46; }

.badge-low      { background: #f1f5f9; color: #475569; }
.badge-normal   { background: var(--lightest); color: #1d4ed8; }
.badge-high     { background: #fff7ed; color: #c2410c; }
.badge-urgent   { background: var(--danger-bg); color: #991b1b; }

.badge-active   { background: var(--success-bg); color: #065f46; }
.badge-pending  { background: var(--warning-bg); color: #92400e; }
.badge-inactive { background: #f1f5f9; color: #475569; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-super_admin { background: #ede9fe; color: #5b21b6; }
.role-purchaser   { background: var(--lightest); color: #1d4ed8; }
.role-requester   { background: var(--bg); color: var(--text-muted); }

/* === Alerts & Flash === */
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.875rem;
  font-weight: 500;
}
.flash-success { background: var(--success-bg); color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: var(--danger-bg);  color: #991b1b; border: 1px solid #fca5a5; }
.flash-warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fcd34d; }
.flash-info    { background: var(--info-bg);    color: #1e40af; border: 1px solid #93c5fd; }
.flash-close { background: none; border: none; cursor: pointer; font-size: 1rem; opacity: .5; }
.flash-close:hover { opacity: 1; }

.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.875rem;
  border-left: 4px solid;
}
.alert-success { background: var(--success-bg); border-color: var(--success); color: #065f46; }
.alert-error   { background: var(--danger-bg);  border-color: var(--danger);  color: #991b1b; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: #92400e; }
.alert-info    { background: var(--info-bg);    border-color: var(--info);    color: #1e40af; }

/* === Login / Auth Pages === */
.auth-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, var(--dark-blue) 50%, var(--mid-blue) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo h1 {
  color: var(--navy);
  font-size: 1.4rem;
  font-weight: 800;
  margin-top: 8px;
}
.auth-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }
.auth-logo .logo-icon {
  width: 60px;
  height: 60px;
  background: var(--primary);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  font-size: 1.6rem;
}

/* === Dashboard Charts === */
.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.chart-bar-label { width: 90px; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-align: right; flex-shrink: 0; }
.chart-bar-track { flex: 1; background: var(--bg); border-radius: 6px; height: 28px; overflow: hidden; }
.chart-bar-fill {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding-left: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  min-width: 32px;
  transition: width .7s cubic-bezier(.4,0,.2,1);
}
.chart-bar-fill.received { background: var(--warning); }
.chart-bar-fill.progress { background: var(--primary); }
.chart-bar-fill.finished { background: var(--success); }
.chart-count { font-weight: 700; font-size: 0.875rem; color: var(--text-primary); width: 30px; text-align: right; flex-shrink: 0; }

/* === Admin Sections === */
.admin-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  gap: 4px;
}
.admin-tab {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 6px 6px 0 0;
  transition: all var(--transition);
  text-decoration: none;
}
.admin-tab:hover { color: var(--primary); background: var(--lightest); text-decoration: none; }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--lightest); }

/* Permissions Matrix */
.perm-matrix { width: 100%; border-collapse: collapse; }
.perm-matrix th { background: var(--dark-blue); color: var(--text-light); padding: 10px 16px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .05em; }
.perm-matrix td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.perm-matrix tr:hover td { background: var(--lightest); }
.perm-toggle { width: 20px; height: 20px; cursor: pointer; accent-color: var(--primary); }

/* === Site Footer === */
.site-footer-bar {
  background: var(--navy);
  padding: 14px 20px;
  margin-top: auto;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255,255,255,.5);
  font-size: 0.8rem;
}
.footer-sep { opacity: .3; }

/* === Utility === */
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 0.8rem; }
.text-center { text-align: center; }
.mt-1  { margin-top: 4px; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 16px; }
.mt-4  { margin-top: 24px; }
.mb-4  { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* Sample data warning */
.sample-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
  vertical-align: middle;
  margin-left: 6px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 440px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-box h3 { margin-bottom: 10px; color: var(--navy); }
.modal-box p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* === Responsive === */
@media (max-width: 768px) {
  .hamburger { display: flex; }
  .site-nav  { display: none; }
  .user-name { display: none; }
  .brand-name { font-size: 0.95rem; }
  .page-content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.three { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; }
  .auth-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .table-wrap { border-radius: 8px; }
  tbody td { font-size: 0.8rem; padding: 10px 12px; }
  thead th { padding: 10px 12px; }
}
