:root {
  --primary: #951B1E;
  --primary-dark: #7a1619;
  --dark: #212529;
  --secondary: #6C757D;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dee2e6;
  --success: #198754;
  --danger: #dc3545;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(33, 37, 41, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--dark);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Auth */
.auth-layout { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; }
.auth-brand {
  background: linear-gradient(145deg, var(--dark) 0%, #3a3f44 60%, var(--primary) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 3rem;
}
.brand-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; margin-bottom: 1.5rem;
}
.brand-logo.sm { width: 40px; height: 40px; font-size: 1.1rem; border-radius: 10px; margin: 0; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-card {
  background: var(--surface); border-radius: var(--radius); padding: 2rem;
  width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.auth-subtitle { color: var(--secondary); margin-top: 0; }
.auth-footer { margin-top: 1.25rem; font-size: 0.9rem; color: var(--secondary); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.9rem; }
input, select, textarea {
  width: 100%; padding: 0.65rem 0.75rem; border: 1px solid var(--border);
  border-radius: 8px; font: inherit;
}
.input-readonly { background: #f8f9fa; color: var(--secondary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1rem; border-radius: 8px; border: none; cursor: pointer;
  font: inherit; font-weight: 600; transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e9ecef; color: var(--dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost { background: transparent; color: #cbd5e1; border: 1px solid #475569; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-error { background: #f8d7da; color: #842029; }

/* App shell */
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--dark); color: #e9ecef; padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.sidebar-brand { display: flex; gap: 0.75rem; align-items: center; }
.brand-title { font-weight: 700; }
.brand-subtitle { font-size: 0.8rem; color: #adb5bd; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none; color: #ced4da;
  padding: 0.65rem 0.75rem; border-radius: 8px; cursor: pointer; font: inherit;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-user { display: flex; gap: 0.65rem; align-items: center; font-size: 0.85rem; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.main-content { padding: 1.5rem 2rem; overflow: auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.25rem; }
.page-desc { color: var(--secondary); margin: 0.25rem 0 0; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Tables */
.table-panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-panel-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.data-table th { background: #f8f9fa; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--secondary); }
.data-table-wrapper { overflow-x: auto; }

/* States */
.loading-state, .empty-state { padding: 2rem; text-align: center; color: var(--secondary); }
.status-badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.status-generated { background: #d1e7dd; color: #0f5132; }
.status-sent { background: #cfe2ff; color: #084298; }
.status-pending { background: #fff3cd; color: #664d03; }
.btn-approved { background: #adb5bd; color: #fff; cursor: default; }
.status-cell { min-width: 140px; }

/* Toast */
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }
.toast {
  background: var(--dark); color: #fff; padding: 0.75rem 1rem; border-radius: 8px;
  margin-bottom: 0.5rem; opacity: 0; transform: translateY(-8px); transition: all 0.25s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); }

/* Compose */
.compose-shell { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.compose-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; }
.compose-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; }
.compose-panel { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
#editor { min-height: 320px; background: #fff; }
.ql-editor { text-align: left; min-height: 280px; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.6; }
.recipient-rows { display: flex; flex-direction: column; gap: 0.5rem; }
.recipient-section { margin-top: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.recipient-row { display: grid; grid-template-columns: 1fr 1.2fr 36px; gap: 0.5rem; align-items: center; }
.recipient-row-header { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--secondary); margin-bottom: 0.15rem; }
.recipient-row-header span:last-child { visibility: hidden; }
.recipient-row input, .recipient-row select { margin: 0; width: 100%; }
#vendor-picker { min-height: 160px; }
#vendor-picker:disabled { background: #f8f9fa; color: var(--secondary); }
.remove-recipient-btn {
  width: 36px; height: 36px; padding: 0; cursor: pointer;
  color: var(--dark); border: 1px solid var(--border); border-radius: 8px; background: #fff;
  font-size: 1.25rem; line-height: 1;
}
.remove-recipient-btn:hover { background: #f8f9fa; }
#add-recipient-btn, #add-selected-vendors-btn { cursor: pointer; }
#add-selected-vendors-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.quotation-card { margin-bottom: 1rem; }
.quotation-card-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; }
.quotation-text { white-space: pre-wrap; background: #f8f9fa; padding: 1rem; border-radius: 8px; text-align: left; font-family: inherit; font-size: 0.9rem; margin: 0; }
.back-link { font-size: 0.9rem; color: var(--secondary); }
.compose-meta { color: var(--secondary); margin: 0.35rem 0 0; }
.hint { font-size: 0.8rem; color: var(--secondary); }
.empty-compose { text-align: center; padding: 4rem; background: var(--surface); border-radius: var(--radius); }

/* Admin */
.admin-topbar {
  background: var(--dark); color: #fff; padding: 1rem 1.5rem;
  display: flex; justify-content: space-between; align-items: center;
}
.admin-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; padding: 1.5rem; }
.admin-kpi-card { background: var(--surface); padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi-label { display: block; font-size: 0.8rem; color: var(--secondary); }
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
.admin-charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; padding: 0 1.5rem 1.5rem; }
.admin-tables-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; padding: 0 1.5rem 2rem; }
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.chart-card h2 { margin: 0 0 1rem; font-size: 1rem; }
.chart-card-wide { grid-column: 1 / -1; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap-tall { height: 220px; }

@media (max-width: 900px) {
  .auth-layout, .app-shell, .compose-grid { grid-template-columns: 1fr; }
  .admin-charts-grid, .admin-tables-grid { grid-template-columns: 1fr; }
  .recipient-row { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
}
