/* TruTrak — Global Styles — Mobile Responsive */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 230px;
  --navy: #1e3a5f;
  --navy-light: #2a4f80;
  --accent: #2563eb;
  --bg: #f0eff9;
  --surface: #ffffff;
  --border: #e2e0f0;
  --text: #1a1a2e;
  --muted: #6b6b8a;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --radius-lg: 12px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar { width: var(--sidebar-w); background: var(--navy); display: flex;
  flex-direction: column; flex-shrink: 0; position: fixed; top: 0; left: 0;
  height: 100vh; overflow-y: auto; z-index: 100; transition: transform .25s ease; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1); }
.logo-icon { background: rgba(255,255,255,.15); color: #fff; font-weight: 700; font-size: 13px;
  padding: 6px 8px; border-radius: 6px; letter-spacing: .05em; }
.logo-icon.lg { font-size: 18px; padding: 10px 12px; }
.logo-text { color: #fff; font-weight: 600; font-size: 14px; }
.sidebar-nav { flex: 1; padding: .75rem; }
.nav-section-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: rgba(255,255,255,.4); padding: .5rem .5rem .25rem; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius); color: rgba(255,255,255,.75); text-decoration: none;
  font-size: 13px; margin-bottom: 2px; transition: background .15s; }
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 500; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: .5rem; margin-bottom: .5rem; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.2);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-avatar.sm { width: 28px; height: 28px; font-size: 12px; background: var(--accent); color: #fff; }
.user-name { color: #fff; font-size: 13px; font-weight: 500; }
.user-role { color: rgba(255,255,255,.5); font-size: 11px; }
.logout-btn { display: block; text-align: center; padding: 7px; border-radius: var(--radius);
  background: rgba(255,255,255,.08); color: rgba(255,255,255,.7); text-decoration: none; font-size: 12px; }
.logout-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Mobile sidebar toggle */
.sidebar-toggle { display: none; position: fixed; top: 14px; left: 14px; z-index: 200;
  background: var(--navy); color: #fff; border: none; border-radius: 8px;
  padding: 8px 10px; cursor: pointer; font-size: 18px; line-height: 1; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 99; }

/* ── Main ── */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
  gap: 1rem; position: sticky; top: 0; z-index: 50; }
.page-title { font-size: 18px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.owner-pill { font-size: 12px; padding: 5px 14px; border: 1px solid var(--border);
  border-radius: 20px; background: var(--surface); cursor: pointer; color: var(--muted);
  display: flex; align-items: center; gap: 5px; }
.owner-pill.unlocked { background: #fef3c7; color: #92400e; border-color: #fcd34d; font-weight: 500; }
.content { padding: 1.5rem; flex: 1; }

/* ── Page actions ── */
.page-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 1rem; flex-wrap: wrap; }
.search-bar { display: flex; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.search-bar .form-input { flex: 1; min-width: 120px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: 1rem; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between;
  padding: .875rem 1.25rem; border-bottom: 1px solid var(--border); gap: 1rem; flex-wrap: wrap; }
.card-title { font-size: 14px; font-weight: 600; }
.card-section { padding: .75rem 1.25rem; border-top: 1px solid var(--border); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 1.25rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1rem 1.25rem; }
.stat-card.stat-danger { border-color: #fca5a5; background: #fff5f5; }
.stat-card.stat-owner { border-color: #fcd34d; background: #fffbeb; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: .5rem; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 13px; font-weight: 400; color: var(--muted); display: block; margin-top: 2px; }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead { background: #f8f7fd; }
.table th { padding: 9px 12px; text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #faf9ff; }
.row-overdue td { background: #fff5f5 !important; }
.row-overdue td:first-child { border-left: 3px solid var(--danger); }
.row-inactive td { opacity: .55; }
.table-actions { white-space: nowrap; text-align: right; }
.owner-col { background: #fffbeb !important; }
th.owner-col { color: #92400e !important; }

/* ── Detail list ── */
.detail-list { padding: 1.25rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.detail-list > div { display: flex; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.detail-list > div:last-child { border-bottom: none; }
.detail-list dt { min-width: 150px; font-size: 12px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; padding-top: 1px; }
.detail-list dd { flex: 1; font-size: 13px; }
.owner-row { background: #fffbeb !important; }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-draft        { background: #f1f5f9; color: #475569; }
.badge-confirmed    { background: #dbeafe; color: #1e40af; }
.badge-in_transit,.badge-inprogress,.badge-in_progress { background: #fef3c7; color: #92400e; }
.badge-completed    { background: #dcfce7; color: #15803d; }
.badge-cancelled    { background: #fee2e2; color: #991b1b; }
.badge-pending      { background: #f1f5f9; color: #475569; }
.badge-booked       { background: #dbeafe; color: #1e40af; }
.badge-loaded       { background: #e0e7ff; color: #3730a3; }
.badge-arrived      { background: #d1fae5; color: #065f46; }
.badge-shipped      { background: #e0e7ff; color: #3730a3; }
.badge-admin        { background: #fce7f3; color: #9d174d; }
.badge-staff        { background: #e0e7ff; color: #3730a3; }
.badge-sent         { background: #dbeafe; color: #1e40af; }
.badge-partiallypaid,.badge-partially_paid { background: #fef3c7; color: #92400e; }
.badge-paid         { background: #dcfce7; color: #15803d; }
.badge-overdue      { background: #fee2e2; color: #991b1b; }
.badge-final        { background: #dcfce7; color: #15803d; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 11.5px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; }
.form-input { font-size: 13px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  outline: none; width: 100%; transition: border-color .15s; font-family: inherit; }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.form-input { resize: vertical; min-height: 72px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end;
  padding-top: 1rem; margin-top: .5rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.owner-field .form-label::before { content: '🔓 '; }
.owner-field .form-input { background: #fffbeb; border-color: #fcd34d; }
.total-display { font-size: 20px; font-weight: 700; color: var(--text); padding: .5rem 0; }
.fsect { grid-column: 1/-1; font-size: 10.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; padding-top: 4px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 5px; padding: 7px 16px;
  border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer;
  text-decoration: none; border: 1px solid transparent; white-space: nowrap;
  transition: all .15s; }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: var(--navy-light); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fee2e2; }
.btn-block { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.ibtn { background: none; border: none; cursor: pointer; font-size: 11px;
  padding: 3px 7px; border-radius: 5px; color: var(--muted); }
.ibtn:hover { background: var(--bg); color: var(--text); }
.ibtn.dl:hover { background: #fee2e2; color: var(--danger); }

/* ── Modals ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 1rem 2rem; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); width: 100%; max-width: 600px; }
.modal-header { display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 22px;
  color: var(--muted); line-height: 1; }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end;
  padding: .875rem 1.25rem; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* ── Alerts ── */
.alert { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: 13px; font-weight: 500; transition: opacity .5s; }
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Login ── */
.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--navy); padding: 1rem; }
.login-wrap { width: 100%; max-width: 420px; }
.login-card { background: var(--surface); border-radius: var(--radius-lg);
  padding: 2.5rem 2rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); margin-top: .75rem; }
.login-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.login-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 1rem; }

/* ── Utilities ── */
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted   { color: var(--muted); }
.text-center  { text-align: center; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.mb-3 { margin-bottom: .75rem; }
.mt-2 { margin-top: .5rem; }
.user-row { display: flex; align-items: center; gap: 8px; }

/* ── AI Chat ── */
.ai-chat-btn { position: fixed; bottom: 1.5rem; right: 1.5rem; width: 52px; height: 52px;
  border-radius: 50%; background: var(--navy); color: #fff; border: none; cursor: pointer;
  font-size: 22px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); z-index: 300; transition: transform .2s; }
.ai-chat-btn:hover { transform: scale(1.08); }
.ai-chat-panel { position: fixed; bottom: 5rem; right: 1.5rem; width: 360px;
  max-height: 520px; background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: 0 8px 32px rgba(0,0,0,.15);
  z-index: 300; display: flex; flex-direction: column; overflow: hidden; }
.ai-chat-header { background: var(--navy); color: #fff; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; }
.ai-chat-header h4 { font-size: 13px; font-weight: 600; }
.ai-chat-close { background: none; border: none; color: rgba(255,255,255,.8);
  cursor: pointer; font-size: 18px; line-height: 1; }
.ai-chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex;
  flex-direction: column; gap: 10px; }
.ai-msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; }
.ai-msg.user { background: var(--navy); color: #fff; align-self: flex-end; border-radius: 12px 12px 0 12px; }
.ai-msg.assistant { background: var(--bg); color: var(--text); align-self: flex-start; border-radius: 12px 12px 12px 0; }
.ai-msg.loading { color: var(--muted); font-style: italic; }
.ai-chat-input { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.ai-chat-input input { flex: 1; font-size: 13px; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); outline: none; background: var(--surface); }
.ai-chat-input input:focus { border-color: var(--accent); }
.ai-chat-input button { padding: 7px 12px; background: var(--navy); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 13px; }

/* ════════════════════════════════════════
   MOBILE RESPONSIVE
   ════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Show toggle button */
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }

  /* Sidebar slides in/out */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  /* Main takes full width */
  .main { margin-left: 0; }

  /* Topbar */
  .topbar { padding: .75rem 1rem .75rem 56px; }
  .page-title { font-size: 15px; }

  /* Content */
  .content { padding: 1rem; }

  /* Grids go single column */
  .two-col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .detail-list { grid-template-columns: 1fr; }

  /* Stats smaller */
  .stat-value { font-size: 18px; }
  .stat-card { padding: .75rem 1rem; }

  /* Tables scroll horizontally */
  .card { overflow-x: auto; }
  .table { min-width: 500px; }
  .table td, .table th { padding: 7px 8px; font-size: 12px; }

  /* Page actions wrap */
  .page-actions { gap: 6px; }
  .search-bar { width: 100%; }
  .btn { font-size: 12px; padding: 6px 12px; }

  /* Modal full screen on mobile */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; overflow-y: auto; }

  /* AI chat panel */
  .ai-chat-panel { width: calc(100vw - 2rem); right: 1rem; bottom: 5.5rem; }

  /* Hide long text in table cells */
  .table-actions .btn-sm { padding: 3px 7px; font-size: 11px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 16px; }
  .topbar { padding-left: 52px; }
}
