:root {
  --primary: #1a3a5c;
  --primary-dark: #122840;
  --accent: #f57c00;
  --accent-light: #fff3e0;
  --sidebar-w: 230px;
  --bg: #f0f4f8;
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: #222;
}

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--primary);
  display: flex; flex-direction: column;
  z-index: 200;
}

.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.logo-mark {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 14px; color: #fff; flex-shrink: 0;
}

.logo-name {
  font-size: 16px; font-weight: 800;
  color: #fff; letter-spacing: 1.5px;
}

.logo-sub {
  font-size: 9px; color: rgba(255,255,255,0.55);
  letter-spacing: 0.5px;
}

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }

.nav-divider {
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,0.35);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 13px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active {
  background: rgba(255,255,255,0.12); color: #fff;
  border-left-color: var(--accent);
}
.nav-item i { width: 16px; text-align: center; font-size: 13px; }

.sidebar-user {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user-info {
  display: flex; align-items: center; gap: 9px; margin-bottom: 8px;
}

.sidebar-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.7); font-size: 12px; flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 12px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 140px;
}

.sidebar-user-role {
  font-size: 10px; color: rgba(255,255,255,0.45);
}

.sidebar-user-actions {
  display: flex; gap: 10px; justify-content: flex-end; padding: 0 2px;
}

.sidebar-user-actions a {
  color: rgba(255,255,255,0.35);
  font-size: 14px; text-decoration: none;
  transition: color 0.15s;
}

.sidebar-user-actions a:hover { color: #fff; }

/* ── MAIN ────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 24px;
}

/* ── PAGE HEADER ─────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}

.page-header h2 {
  font-size: 20px; font-weight: 700;
  color: var(--primary); margin: 0;
}

.page-header .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── CARDS ───────────────────────────────────── */
.card {
  border: none;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.stat-card {
  background: #fff;
  border-radius: 10px;
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  display: flex; align-items: center; gap: 16px;
  height: 100%;
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}

.stat-value { font-size: 26px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 3px; }

/* ── TABLE WRAPPER ───────────────────────────── */
.table-wrap {
  background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow: hidden;
}

.table-wrap-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #f0f0f0;
  flex-wrap: wrap; gap: 8px;
}

.table-wrap-header h5 {
  margin: 0; font-size: 14px; font-weight: 600;
  color: var(--primary);
}

.table { margin-bottom: 0; font-size: 13px; }

.table thead th {
  background: #f5f7fa;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: #666;
  border-top: none;
  border-bottom: 1px solid #e8e8e8;
  padding: 9px 14px;
  white-space: nowrap;
}

.table tbody td {
  padding: 9px 14px;
  vertical-align: middle;
  border-bottom: 1px solid #f5f5f5;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafbff; }

/* ── STATUS BADGES ───────────────────────────── */
.badge { font-size: 11px; font-weight: 600; border-radius: 4px; padding: 3px 8px; }

.s-draft     { background:#e9ecef; color:#555; }
.s-sent      { background:#fff3cd; color:#856404; }
.s-accepted  { background:#d1e7dd; color:#0f5132; }
.s-rejected  { background:#f8d7da; color:#842029; }

.s-booking   { background:#e9ecef; color:#555; }
.s-confirmed { background:#cfe2ff; color:#084298; }
.s-loading   { background:#fff3cd; color:#856404; }
.s-in-transit{ background:#d1ecf1; color:#0c5460; }
.s-arrived   { background:#d1e7dd; color:#0f5132; }
.s-delivered { background:#c3e6cb; color:#155724; }
.s-completed { background:#198754; color:#fff; }
.s-cancelled { background:#f8d7da; color:#842029; }
.bg-purple    { background:#7c3aed !important; color:#fff !important; }

.s-draft-doc     { background:#e9ecef; color:#555; }
.s-submitted { background:#cfe2ff; color:#084298; }
.s-approved  { background:#fff3cd; color:#856404; }
.s-issued    { background:#d1e7dd; color:#0f5132; }

/* ── BUTTONS ─────────────────────────────────── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #e65100; border-color: #e65100; color: #fff; }

.btn-icon { padding: 3px 7px; font-size: 12px; }

/* ── MODAL ───────────────────────────────────── */
.modal-header { background: var(--primary); color: #fff; border-radius: 0; }
.modal-title { font-size: 15px; font-weight: 600; }
.btn-close { filter: invert(1); }

/* ── ITEMS TABLE (quote) ─────────────────────── */
#items-container table thead th { background: var(--primary); color: #fff; font-size: 11px; padding: 7px 6px; }
#items-container table tbody td { padding: 5px 4px; }
#items-container input, #items-container select { font-size: 12px; padding: 4px 6px; height: 32px; min-height: 32px; }
#items-container input[type="number"] { -moz-appearance: textfield; }
#items-container input[type="number"]::-webkit-inner-spin-button { opacity: 1; }

/* ── FORM ────────────────────────────────────── */
.form-label { font-size: 12px; font-weight: 600; color: #555; margin-bottom: 3px; }
.form-control, .form-select { font-size: 13px; }
.section-title {
  font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 6px; margin: 16px 0 12px;
}

/* ── MISC ────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 40px 20px;
  color: #aaa;
}
.empty-state i { font-size: 40px; margin-bottom: 10px; display: block; }

.search-wrap { position: relative; }
.search-wrap input { padding-left: 32px; font-size: 13px; }
.search-wrap i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 13px; }

.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── TOAST ───────────────────────────────────── */
.toast-item {
  background: #fff; border-radius: 8px;
  padding: 12px 16px; margin-top: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 260px;
  display: flex; align-items: center; gap: 10px;
  animation: slideIn 0.3s ease;
  border-left: 4px solid #28a745;
}
.toast-item.error { border-left-color: #dc3545; }
.toast-item.warn  { border-left-color: #ffc107; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ── LOGIN PAGE ───────────────────────────────── */
#login-page {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

.login-card {
  background: #fff; border-radius: 16px;
  padding: 40px 36px; width: 360px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.login-logo { text-align: center; margin-bottom: 16px; }

.login-logo .logo-mark {
  width: 56px; height: 56px; font-size: 20px;
  margin: 0 auto;
}

.login-title {
  text-align: center; font-size: 19px; font-weight: 800;
  color: var(--primary); letter-spacing: 1.5px; margin-bottom: 4px;
}

.login-sub {
  text-align: center; font-size: 12px; color: #999;
  margin-bottom: 28px;
}

/* ── AI MODULES ─────────────────────────────── */
.ai-loading { padding: 8px 0; }

.ai-stream-preview {
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.6;
  color: #555;
  max-height: 300px;
  overflow-y: auto;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 10px 14px;
  border: 1px solid #e8e8e8;
}

/* Kết quả render markdown */
.ai-result {
  font-size: 13px;
  line-height: 1.75;
  color: #333;
}
.ai-result h1, .ai-result h2, .ai-result h3,
.ai-result h4, .ai-result h5, .ai-result h6 {
  color: var(--primary);
  margin: 16px 0 8px;
  font-weight: 700;
}
.ai-result h3 { font-size: 15px; }
.ai-result h4 { font-size: 14px; }
.ai-result p  { margin: 6px 0; }
.ai-result ul, .ai-result ol { padding-left: 20px; margin: 6px 0; }
.ai-result li { margin: 4px 0; }
.ai-result strong { color: #1a3a5c; }
.ai-result table {
  width: 100%; border-collapse: collapse;
  font-size: 12px; margin: 12px 0;
}
.ai-result table th {
  background: var(--primary); color: #fff;
  padding: 7px 10px; text-align: left;
  font-size: 11px; font-weight: 600;
}
.ai-result table td {
  padding: 6px 10px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
.ai-result table tr:nth-child(even) td { background: #f8f9fa; }
.ai-result table tr:hover td { background: #eef2ff; }
.ai-result blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 12px; margin: 8px 0;
  background: var(--accent-light); border-radius: 0 4px 4px 0;
  font-style: italic; color: #666;
}
.ai-result code {
  background: #f0f4f8; padding: 1px 5px;
  border-radius: 3px; font-size: 12px; color: #e65100;
}
.ai-result pre {
  background: #f0f4f8; padding: 10px 14px;
  border-radius: 6px; overflow-x: auto;
  font-size: 12px; line-height: 1.5;
}
.ai-result hr { border: none; border-top: 1px solid #e8e8e8; margin: 14px 0; }

.ai-result-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid #f0f0f0;
}

/* ── RESPONSIVE ──────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar .logo-name, .sidebar .logo-sub, .nav-item span, .nav-divider,
  .sidebar-user-name, .sidebar-user-role, .sidebar-user-actions { display: none; }
  .main-content { margin-left: 60px; padding: 16px; }
}
