/* ═══════════════════════════════════════════════════════════════════
   CEDAR COFFEE — Design System v2
   Palette: White / Green / Slate
   Type: Inter (Google-style clean)
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --green:      #1B7A4A;
  --green-dk:   #145C38;
  --green-lt:   #E8F5EE;
  --green-mid:  #2E9E61;
  --accent:     #F0A500;
  --slate:      #6B7280;
  --slate-lt:   #9CA3AF;
  --slate-xlt:  #E5E7EB;
  --espresso:   #111827;
  --white:      #FFFFFF;
  --page-bg:    #F9FAFB;
  --card-bg:    #FFFFFF;
  --border:     #E5E7EB;
  --border-md:  #D1D5DB;
  --danger:     #DC2626;
  --success:    #16A34A;
  --warn:       #D97706;

  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --topbar-h: 58px;
  --nav-h: 62px;
  --sidebar-w: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--page-bg);
  color: var(--espresso);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── LOGIN ──────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f4c2a 0%, #1B7A4A 60%, #2E9E61 100%);
  padding: 24px;
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-icon {
  width: 56px;
  height: 56px;
  background: var(--green-lt);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 16px;
}
.login-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--espresso);
  letter-spacing: -0.02em;
}
.login-brand p {
  font-size: 13px;
  color: var(--slate);
  margin-top: 4px;
}
.login-error {
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: var(--danger);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font-size: 13px;
  margin-bottom: 16px;
}
.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 11px;
  color: var(--slate-lt);
  letter-spacing: 0.02em;
}

/* ── TOPBAR ─────────────────────────────────────────────────────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar-inner {
  display: flex; align-items: center;
  height: 100%; padding: 0 16px; gap: 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-icon {
  width: 32px; height: 32px;
  background: var(--green);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: white;
}
.brand-name {
  font-size: 16px; font-weight: 700;
  color: var(--espresso); letter-spacing: -0.02em;
}
#topbar-title {
  flex: 1; font-size: 13px; font-weight: 500;
  color: var(--slate); text-align: center;
}
.fab-inline {
  background: var(--green); color: var(--white); border: none;
  border-radius: var(--r-sm); padding: 8px 16px;
  font-size: 13px; font-weight: 600; font-family: 'Inter', sans-serif;
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
  letter-spacing: -0.01em;
}
.fab-inline:hover { background: var(--green-dk); }

/* ── BOTTOM NAV ─────────────────────────────────────────────────── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h); background: var(--white);
  display: flex; border-top: 1px solid var(--border); z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  background: none; border: none; color: var(--slate-lt);
  font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 500;
  cursor: pointer; transition: color 0.15s;
  letter-spacing: 0.02em; text-transform: uppercase;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--green); }
.nav-item:hover  { color: var(--espresso); }

/* ── SIDEBAR ────────────────────────────────────────────────────── */
#sidebar { display: none; }
.sidebar-nav { padding: 8px 0; }
.sidebar-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; color: var(--slate);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all 0.12s; border: none; background: none;
  width: 100%; text-align: left; font-family: 'Inter', sans-serif;
  border-radius: 0; margin: 1px 0;
}
.sidebar-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-nav-item:hover { color: var(--espresso); background: var(--page-bg); }
.sidebar-nav-item.active {
  color: var(--green); background: var(--green-lt);
  font-weight: 600;
}
.sidebar-section {
  padding: 16px 16px 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--slate-lt);
}
.sidebar-user {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--white);
}
.sidebar-user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--green-lt); color: var(--green);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px; font-weight: 600; color: var(--espresso);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11px; color: var(--slate);
  text-transform: capitalize; margin-top: 1px;
}
.sidebar-user-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}

/* ── MAIN CONTENT ───────────────────────────────────────────────── */
#page-content {
  margin-top: var(--topbar-h);
  margin-bottom: var(--nav-h);
  min-height: calc(100vh - var(--topbar-h) - var(--nav-h));
  padding: 20px 16px;
}

/* ── PAGE HEADER ────────────────────────────────────────────────── */
.page-header { margin-bottom: 20px; }
.page-header h1 {
  font-size: 22px; font-weight: 700;
  color: var(--espresso); letter-spacing: -0.02em;
}
.page-header p { font-size: 13px; color: var(--slate); margin-top: 3px; }

/* ── CARDS ──────────────────────────────────────────────────────── */
.card {
  background: var(--card-bg); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card-body { padding: 16px; }
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--slate);
}

/* ── BADGES ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
}
.badge::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}
.badge-pending  { background: #F3F4F6; color: var(--slate); }
.badge-arrived  { background: #FEF3C7; color: #92400E; }
.badge-stored   { background: var(--green-lt); color: var(--green-dk); }
.badge-process  { background: #FEF3C7; color: #92400E; }
.badge-complete { background: #DCFCE7; color: #15803D; }
.badge-active   { background: #DBEAFE; color: #1D4ED8; }

/* ── LIST ROWS ──────────────────────────────────────────────────── */
.list-row {
  display: flex; align-items: center; padding: 14px 16px; gap: 12px;
  cursor: pointer; transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row:hover  { background: var(--page-bg); }
.list-row:active { background: var(--green-lt); }
.row-icon {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 18px;
}
.row-icon-espresso { background: var(--espresso); color: white; }
.row-icon-olive    { background: var(--green-lt); color: var(--green); }
.row-icon-amber    { background: #FEF3C7; color: #92400E; }
.row-info { flex: 1; min-width: 0; }
.row-title {
  font-size: 14px; font-weight: 600; color: var(--espresso);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub { font-size: 12px; color: var(--slate); margin-top: 2px; }
.row-right { text-align: right; flex-shrink: 0; }
.row-weight { font-size: 13px; font-weight: 600; color: var(--espresso); }
.row-date   { font-size: 11px; color: var(--slate-lt); margin-top: 2px; }

/* ── YIELD BAR ──────────────────────────────────────────────────── */
.yield-bar-wrap { margin-top: 10px; }
.yield-bar-label {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--slate); margin-bottom: 5px; font-weight: 500;
  flex-wrap: wrap; gap: 2px;
}
.yield-bar-track {
  height: 6px; background: var(--slate-xlt);
  border-radius: 3px; overflow: hidden; display: flex; gap: 1px;
}
.yield-seg-prime    { background: var(--green); }
.yield-seg-peaberry { background: var(--accent); }
.yield-seg-defects  { background: var(--danger); }
.yield-seg-loss     { background: var(--slate-xlt); }

/* ── STAT GRID ──────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 16px;
}
.stat-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--slate);
}
.stat-value {
  font-size: 28px; font-weight: 700; color: var(--espresso);
  line-height: 1.1; margin-top: 6px; letter-spacing: -0.03em;
}
.stat-unit  { font-size: 14px; color: var(--slate); font-weight: 400; }
.stat-delta { font-size: 11px; margin-top: 4px; font-weight: 500; }
.stat-delta.up   { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ── FORMS ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--espresso); margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border-md); border-radius: var(--r-sm);
  font-family: 'Inter', sans-serif; font-size: 14px;
  color: var(--espresso); background: var(--white);
  outline: none; transition: border-color 0.15s;
  appearance: none; -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(27,122,74,0.1);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── BUTTONS ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; border: none; border-radius: var(--r-sm);
  font-family: 'Inter', sans-serif; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
  letter-spacing: -0.01em;
}
.btn-primary   { background: var(--green); color: var(--white); }
.btn-primary:hover   { background: var(--green-dk); }
.btn-secondary { background: var(--espresso); color: var(--white); }
.btn-secondary:hover { opacity: 0.85; }
.btn-ghost     { background: transparent; color: var(--espresso); border: 1.5px solid var(--border-md); }
.btn-ghost:hover     { background: var(--page-bg); }
.btn-danger    { background: #FEF2F2; color: var(--danger); border: 1.5px solid #FECACA; }
.btn-danger:hover    { background: #FEE2E2; }
.btn-sm   { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-row  { display: flex; gap: 10px; margin-top: 20px; }
.btn-row .btn { flex: 1; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── SECTION LABEL ──────────────────────────────────────────────── */
.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--slate-lt);
  margin: 20px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── DETAIL ROWS ────────────────────────────────────────────────── */
.detail-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border); gap: 12px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key { font-size: 12px; color: var(--slate); font-weight: 500; flex-shrink: 0; }
.detail-val { font-size: 13px; font-weight: 600; color: var(--espresso); text-align: right; }

/* ── GRADE GRID ─────────────────────────────────────────────────── */
.grade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grade-item {
  background: var(--page-bg); border-radius: var(--r-sm);
  padding: 12px; border: 1px solid var(--border);
  border-left: 3px solid var(--border-md);
}
.grade-item.prime    { border-left-color: var(--green); }
.grade-item.peaberry { border-left-color: var(--accent); }
.grade-item.defect   { border-left-color: var(--danger); }
.grade-item.neutral  { border-left-color: var(--slate-lt); }
.grade-name { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--slate); }
.grade-kg   { font-size: 20px; font-weight: 700; color: var(--espresso); margin-top: 4px; letter-spacing: -0.02em; }
.grade-pct  { font-size: 11px; color: var(--slate-lt); margin-top: 2px; }

/* ── SUPPLIER ───────────────────────────────────────────────────── */
.supplier-row { padding: 14px 16px; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.supplier-row:last-child { border-bottom: none; }
.supplier-row:hover { background: var(--page-bg); }
.supplier-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.supplier-name { font-size: 14px; font-weight: 600; color: var(--espresso); }
.supplier-pct  { font-size: 15px; font-weight: 700; color: var(--green); }
.supplier-bar-track { height: 6px; background: var(--slate-xlt); border-radius: 3px; overflow: hidden; }
.supplier-bar-fill  { height: 100%; background: var(--green); border-radius: 3px; transition: width 0.6s ease; }
.supplier-meta { display: flex; gap: 12px; margin-top: 6px; font-size: 11px; color: var(--slate-lt); flex-wrap: wrap; }

/* ── STEP INDICATOR ─────────────────────────────────────────────── */
.step-indicator { display: flex; align-items: center; margin-bottom: 20px; }
.step-dot {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--page-bg); border: 2px solid var(--border-md);
  color: var(--slate-lt); font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: all 0.2s;
}
.step-dot.done   { background: var(--green); border-color: var(--green); color: white; }
.step-dot.active { background: var(--green-lt); border-color: var(--green); color: var(--green); }
.step-line { flex: 1; height: 2px; background: var(--border-md); }
.step-line.done { background: var(--green); }

/* ── LORRY ID ───────────────────────────────────────────────────── */
.lorry-id { font-size: 18px; font-weight: 700; color: var(--green); letter-spacing: -0.01em; }

/* ── LOADING / ERROR ────────────────────────────────────────────── */
.loading-state { text-align: center; padding: 40px; color: var(--slate); font-size: 14px; }
.err { color: var(--danger); font-size: 13px; padding: 12px 0; }
.empty-state { text-align: center; padding: 48px 24px; color: var(--slate); }
.empty-state .es-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--espresso); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; line-height: 1.5; }

/* ── MODAL ──────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 200; align-items: flex-end; justify-content: center;
}
#modal-card {
  background: var(--white); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 600px; max-height: 92vh;
  overflow-y: auto; animation: slideUp 0.22s ease;
}
@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
#modal-title { font-size: 17px; font-weight: 700; color: var(--espresso); letter-spacing: -0.02em; }
#modal-close {
  background: var(--page-bg); border: none; font-size: 16px;
  color: var(--slate); cursor: pointer; padding: 6px 8px;
  border-radius: 6px; line-height: 1;
}
#modal-close:hover { background: var(--border); color: var(--espresso); }
#modal-body { padding: 20px; }

/* ── TOAST ──────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--espresso); color: white;
  padding: 10px 20px; border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  opacity: 0; transition: all 0.25s; pointer-events: none;
  z-index: 300; border-left: 3px solid var(--green);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── DESKTOP ────────────────────────────────────────────────────── */
@media (min-width: 1024px) {
  #sidebar {
    display: block; position: fixed;
    top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--border);
    z-index: 100; overflow-y: auto;
  }
  #bottom-nav { display: none !important; }
  .topbar-inner { padding-left: calc(var(--sidebar-w) + 20px); }
  #page-content {
    margin-left: var(--sidebar-w); margin-bottom: 0;
    padding: 28px 36px; max-width: 1200px;
  }
  #modal-overlay { align-items: center; }
  #modal-card {
    border-radius: 16px; max-height: 85vh;
    margin-left: calc(var(--sidebar-w) / 2);
  }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  #toast { bottom: 20px; }
}
