/* ============================================================
   Purchase Order Management System - UI styles
   ============================================================ */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --genius: #e11d2a;
  --active: #0ea5e9;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 16px rgba(15, 23, 42, .08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .18);
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: var(--success); }
.btn.success:hover { background: #15803d; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Company selection screen ---------- */
.select-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: radial-gradient(1200px 600px at 50% -10%, #dbeafe, var(--bg));
}
.select-screen h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -.5px; }
.select-screen .sub { color: var(--muted); margin: 0 0 36px; }
.company-cards { display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; }
.company-card {
  width: 250px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.company-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.company-badge {
  width: 76px; height: 76px;
  border-radius: 20px;
  margin: 0 auto 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 800; color: #fff;
}
.company-badge.genius { background: transparent; padding: 0; overflow: hidden; }
.company-badge.active { background: var(--active); }
.company-logo-img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 20px; }
.company-card h2 { margin: 0 0 4px; font-size: 19px; }
.company-card p { color: var(--muted); font-size: 13px; margin: 0 0 20px; min-height: 34px; }

/* ---------- Login ---------- */
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  text-align: left;
}
.login-card .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.login-card .field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
}
.login-card .field input:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
  background: var(--surface);
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0 0 12px;
}
.login-error.hidden { display: none; }
.sidebar-user {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  word-break: break-word;
}

/* ---------- App layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
  width: 40px; height: 40px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; color: #fff; margin-bottom: 10px;
}
.sidebar .brand .logo.genius { background: var(--genius); }
.sidebar .brand .logo.active { background: var(--active); }
.sidebar .brand .sidebar-logo-img { width: 40px; height: 40px; object-fit: cover; border-radius: 11px; display: block; margin-bottom: 10px; }
.sidebar .brand .name { color: #fff; font-weight: 700; font-size: 15px; }
.sidebar .brand .role { font-size: 12px; color: #94a3b8; }
.nav { padding: 14px 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px; border-radius: 10px;
  color: #cbd5e1; font-weight: 500; font-size: 14px;
  margin-bottom: 3px;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a .ic { width: 18px; text-align: center; }
.sidebar .foot { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar .foot button { width: 100%; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-size: 17px; font-weight: 700; }
.topbar .pill {
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
}
.content { padding: 26px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card .card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card .card-head h3 { margin: 0; font-size: 16px; }
.card .card-body { padding: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -.5px; }
.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #334155; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint { font-size: 12px; color: var(--muted); }
.field input[readonly] { background: var(--surface-2); color: var(--muted); }
.field.hidden { display: none; }
.radio-row { display: flex; gap: 20px; flex-wrap: wrap; padding-top: 2px; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; color: var(--text); cursor: pointer; }
.radio-row input { width: auto; margin: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
table.data tbody tr:hover { background: var(--surface-2); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

/* PO item editor table */
table.items { width: 100%; border-collapse: collapse; }
table.items th { padding: 9px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); text-align: left; border-bottom: 1px solid var(--border); }
table.items td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.items input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
table.items input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
table.items .line-total { font-weight: 600; font-variant-numeric: tabular-nums; }
.col-no { width: 46px; color: var(--muted); text-align: center; }
.col-qty { width: 110px; }
.col-price { width: 150px; }
.col-total { width: 150px; }
.col-act { width: 46px; }
.row-del { background: var(--danger-soft); color: var(--danger); border: none; width: 30px; height: 30px; border-radius: 8px; font-size: 16px; line-height: 1; }
.row-del:hover { background: #fee2e2; }

/* totals box */
.totals { margin-top: 18px; display: flex; justify-content: flex-end; }
.totals .box { width: 320px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.totals .line { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .line.grand { border-top: 2px solid var(--border); margin-top: 6px; padding-top: 12px; font-size: 19px; font-weight: 800; }
.totals .line .lbl { color: var(--muted); }
.totals .vat-pill { font-size: 12px; background: var(--primary-soft); color: var(--primary-dark); padding: 2px 8px; border-radius: 999px; margin-left: 6px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.genius { background: #fee2e2; color: var(--genius); }
.badge.active { background: #e0f2fe; color: #0369a1; }
.badge.vat { background: var(--primary-soft); color: var(--primary-dark); }
.badge.zero { background: #f1f5f9; color: var(--muted); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.toolbar .field { min-width: 150px; flex: 1; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 14px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 22px; letter-spacing: -.4px; }
.page-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg); max-height: 90vh; display: flex; flex-direction: column;
}
.modal .modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal .modal-head h3 { margin: 0; font-size: 17px; }
.modal .modal-body { padding: 22px; overflow-y: auto; }
.modal .modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal .x { background: none; border: none; font-size: 22px; color: var(--muted); line-height: 1; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; right: 22px; bottom: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #0f172a; color: #fff; padding: 13px 18px; border-radius: 11px;
  box-shadow: var(--shadow-lg); font-size: 14px; max-width: 360px;
  animation: slideIn .2s ease; border-left: 4px solid var(--primary);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .ic { font-size: 40px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px; justify-content: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.row-actions { display: flex; gap: 6px; }

@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .form-grid { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
