/* ===========================================================
   BuildManager — Design Tokens
   Corporate construction palette. Engineering-document feel.
   =========================================================== */

:root {
  /* Ink (text) */
  --ink:          #0F172A;
  --ink-muted:    #475569;
  --ink-subtle:   #94A3B8;

  /* Surfaces */
  --surface:         #FFFFFF;
  --surface-sunken:  #F8FAFC;
  --surface-raised:  #F1F5F9;

  /* Borders */
  --border:         #E2E8F0;
  --border-strong:  #CBD5E1;

  /* Brand (navy) */
  --brand:        #1E3A5F;
  --brand-hover:  #15304F;
  --brand-soft:   #E8EEF5;

  /* Accent (amber) — KSA warmth */
  --accent:        #D97706;
  --accent-hover:  #B45309;
  --accent-soft:   #FEF3C7;

  /* Semantic */
  --success:       #047857;
  --success-soft:  #D1FAE5;
  --warning:       #D97706;
  --warning-soft:  #FEF3C7;
  --danger:        #B91C1C;
  --danger-soft:   #FEE2E2;
  --info:          #1E40AF;
  --info-soft:     #DBEAFE;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  /* Shadows (reserved — used only on modals/dropdowns) */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 6px rgba(15, 23, 42, 0.04), 0 10px 15px rgba(15, 23, 42, 0.08);
}

/* ---------- Base overrides ----------------------------------- */

html { color: var(--ink); }
body { background: var(--surface-sunken); color: var(--ink); }

/* Tighter, more professional scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-subtle); }

/* Monospace numeric alignment for currency */
.num, .mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- Card ---------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.card-dense { padding: 16px; }
.card-hero  { padding: 24px; }
.card-hover:hover { border-color: var(--border-strong); background: #FCFDFE; cursor: pointer; }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-bottom: 12px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.card-subtitle { font-size: 13px; color: var(--ink-muted); }

/* ---------- Buttons ------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; font-size: 14px; font-weight: 500; line-height: 1;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  transition: background 150ms, color 150ms, border-color 150ms;
  cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-lg { padding: 10px 18px; font-size: 15px; }

.btn-primary {
  background: var(--brand); color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn-accent {
  background: var(--accent); color: #fff;
}
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface); color: var(--ink); border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-raised); }

.btn-danger {
  background: var(--danger); color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #991B1B; }

.btn-ghost {
  background: transparent; color: var(--ink-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-raised); color: var(--ink); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  color: var(--ink-muted); background: transparent;
  transition: background 150ms, color 150ms;
  cursor: pointer; border: none;
}
.icon-btn:hover { background: var(--surface-raised); color: var(--ink); }

/* ---------- Chip / Badge ------------------------------------- */

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; font-size: 11px; font-weight: 600;
  line-height: 18px; border-radius: 9999px;
  border: 1px solid transparent; letter-spacing: 0.02em;
  text-transform: none;
}
.chip-lg { padding: 4px 10px; font-size: 12px; line-height: 20px; }
.chip-uppercase { text-transform: uppercase; letter-spacing: 0.05em; font-size: 10px; }

.chip-neutral { background: var(--surface-raised); color: var(--ink-muted); border-color: var(--border); }
.chip-brand   { background: var(--brand-soft);    color: var(--brand);      border-color: #D6E0EE; }
.chip-success { background: var(--success-soft);  color: var(--success);    border-color: #A7F3D0; }
.chip-warning { background: var(--warning-soft);  color: var(--warning);    border-color: #FDE68A; }
.chip-danger  { background: var(--danger-soft);   color: var(--danger);     border-color: #FECACA; }
.chip-info    { background: var(--info-soft);     color: var(--info);       border-color: #BFDBFE; }
.chip-accent  { background: var(--accent-soft);   color: var(--accent-hover); border-color: #FCD34D; }

/* ---------- Inputs ------------------------------------------- */

.input, .select, .textarea {
  width: 100%; padding: 8px 12px; font-size: 14px; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); line-height: 1.4;
  transition: border-color 150ms, box-shadow 150ms;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.12);
}
.textarea { resize: vertical; min-height: 80px; }
.label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-muted); margin-bottom: 6px; }

/* ---------- Page header -------------------------------------- */

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
.page-title { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1.2; letter-spacing: -0.01em; }
.page-subtitle { font-size: 14px; color: var(--ink-muted); margin-top: 4px; }
.page-breadcrumb { font-size: 12px; color: var(--ink-muted); margin-bottom: 6px; }
.page-breadcrumb a { color: var(--ink-muted); }
.page-breadcrumb a:hover { color: var(--brand); }

/* ---------- KPI card ----------------------------------------- */

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color 150ms, background 150ms;
}
.kpi-clickable { cursor: pointer; }
.kpi-clickable:hover { border-color: var(--border-strong); background: #FCFDFE; }

.kpi-head { display: flex; align-items: center; justify-content: space-between; }
.kpi-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.kpi-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-raised); color: var(--ink-muted);
}
.kpi-icon-brand   { background: var(--brand-soft);   color: var(--brand); }
.kpi-icon-accent  { background: var(--accent-soft);  color: var(--accent-hover); }
.kpi-icon-success { background: var(--success-soft); color: var(--success); }
.kpi-icon-warning { background: var(--warning-soft); color: var(--warning); }
.kpi-icon-danger  { background: var(--danger-soft);  color: var(--danger); }
.kpi-icon-info    { background: var(--info-soft);    color: var(--info); }

.kpi-value {
  font-size: clamp(18px, 2vw, 26px); font-weight: 700; color: var(--ink); line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.kpi-sub { font-size: 12px; color: var(--ink-muted); }

/* ---------- Tabs --------------------------------------------- */

.tabs {
  display: flex; gap: 2px; padding: 4px; background: var(--surface-raised);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  width: fit-content;
}
.tab {
  padding: 6px 14px; font-size: 13px; font-weight: 500; color: var(--ink-muted);
  border-radius: 5px; cursor: pointer; background: transparent;
  border: none; transition: background 150ms, color 150ms;
}
.tab:hover { color: var(--ink); }
.tab-active { background: var(--surface); color: var(--ink); font-weight: 600;
              box-shadow: 0 1px 2px rgba(15,23,42,0.06); }

/* Underline variant (for subnav like Tasks kanban, ProjectDetail) */
.tabs-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab-bar-item {
  padding: 10px 14px; font-size: 13px; font-weight: 500; color: var(--ink-muted);
  border-bottom: 2px solid transparent; cursor: pointer; background: transparent;
  border-top: none; border-left: none; border-right: none;
  transition: color 150ms, border-color 150ms;
}
.tab-bar-item:hover { color: var(--ink); }
.tab-bar-active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* Tabs primitive (src/components/Tabs.js) — defaults to underline variant
   so it drops in next to the existing .tabs-bar usages without extra props.
   Callers can override via `className` / `tabClassName` / `activeTabClassName`. */
.tabs-list {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
}
.tabs-tab {
  padding: 10px 14px; font-size: 13px; font-weight: 500; color: var(--ink-muted);
  border-bottom: 2px solid transparent; cursor: pointer; background: transparent;
  border-top: none; border-left: none; border-right: none;
  transition: color 150ms, border-color 150ms;
}
.tabs-tab:hover { color: var(--ink); }
.tabs-tab:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.tabs-tab-active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs-panel { padding: 16px 0; }
.tabs-panel:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Divider ------------------------------------------ */

.divider { height: 1px; background: var(--border); width: 100%; margin: 16px 0; }

/* ---------- Empty state -------------------------------------- */

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 24px; text-align: center; gap: 10px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-sunken);
}
.empty-icon {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface-raised); color: var(--ink-subtle);
  display: inline-flex; align-items: center; justify-content: center;
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.empty-hint { font-size: 13px; color: var(--ink-muted); max-width: 320px; }

/* ---------- Progress bar ------------------------------------- */

.pbar { width: 100%; height: 6px; background: var(--surface-raised); border-radius: 9999px; overflow: hidden; }
.pbar-fill { height: 100%; background: var(--brand); border-radius: 9999px; transition: width 300ms; }
.pbar-fill-accent  { background: var(--accent); }
.pbar-fill-success { background: var(--success); }
.pbar-fill-warning { background: var(--warning); }
.pbar-fill-danger  { background: var(--danger); }

/* ---------- RTL adjustments ---------------------------------- */

[dir="rtl"] .page-header,
[dir="rtl"] .card-header,
[dir="rtl"] .kpi-head {
  /* flex already works; just ensure text alignment */
}
[dir="rtl"] .chip { flex-direction: row-reverse; }

/* ---------- Utility: line clamp ------------------------------ */
.line-clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Global: defeat ad-hoc rounded-xl for unity ------- */
/* Keep rounded-full; normalize only boxy corners */
.rounded-xl  { border-radius: var(--radius-md) !important; }
.rounded-2xl { border-radius: var(--radius-lg) !important; }

/* ---------- Global: defeat heavy shadow-* on cards ----------- */
.shadow, .shadow-md, .shadow-lg, .shadow-xl { box-shadow: none !important; }

/* ---------- Sidebar (navy) ----------------------------------- */
.sidebar {
  width: 240px; background: var(--brand); color: #E2E8F0;
  display: flex; flex-direction: column; min-height: 100vh;
}
.sidebar-brand {
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo {
  width: 44px; height: 44px; border-radius: 50%; background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brand); flex-shrink: 0; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15), 0 2px 6px rgba(0,0,0,0.25);
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-brand-title { font-weight: 700; font-size: 14px; color: #fff; line-height: 1.2; letter-spacing: 0.01em; }
.sidebar-brand-sub { font-size: 11px; color: #CBD5E1; margin-top: 2px; letter-spacing: 0.02em; }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; font-size: 13.5px; font-weight: 500; color: #CBD5E1;
  border-radius: var(--radius-sm); cursor: pointer; position: relative;
  transition: background 150ms, color 150ms;
  text-decoration: none;
}
.sidebar-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-item-active {
  background: rgba(255,255,255,0.08); color: #fff; font-weight: 600;
}
.sidebar-item-active::before {
  content: ""; position: absolute;
  inset-inline-start: 0; top: 8px; bottom: 8px;
  width: 3px; background: var(--accent); border-radius: 0 2px 2px 0;
}
[dir="rtl"] .sidebar-item-active::before { border-radius: 2px 0 0 2px; }

.sidebar-footer {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-user-name { color: #F1F5F9; font-size: 13px; font-weight: 500; }
.sidebar-user-role { color: #CBD5E1; font-size: 11px; }

/* ---------- Topbar ------------------------------------------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 24px; display: flex; align-items: center; gap: 12px;
  min-height: 52px;
}
.topbar-date { font-size: 13px; color: var(--ink-muted); display: inline-flex; align-items: center; gap: 6px; }
.topbar-lang {
  padding: 5px 10px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-muted); cursor: pointer;
}
.topbar-lang:hover { background: var(--surface-raised); color: var(--ink); }

/* ---------- Page surface ------------------------------------ */
.page { padding: 24px 32px; max-width: 1440px; margin: 0 auto; }
@media (max-width: 768px) { .page { padding: 16px; } }

/* ---------- Table list -------------------------------------- */
.tlist {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden;
}
.tlist-head {
  display: grid; gap: 12px; padding: 10px 16px;
  background: var(--surface-sunken); border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-muted);
}
.tlist-row {
  display: grid; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--border); font-size: 13.5px; color: var(--ink);
  align-items: center;
}
.tlist-row:last-child { border-bottom: none; }
.tlist-row:hover { background: var(--surface-sunken); }

/* ---------- Modal ------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; backdrop-filter: blur(2px);
}
.modal-panel {
  background: var(--surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
  width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-sm { max-width: 420px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 980px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px;
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-sunken);
}

/* ---------- Stripe accents (vertical ribbon) ---------------- */
.ribbon { position: relative; }
.ribbon::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0;
  width: 3px; background: var(--ink-subtle); border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md);
}
.ribbon-danger::before  { background: var(--danger); }
.ribbon-warning::before { background: var(--warning); }
.ribbon-success::before { background: var(--success); }
.ribbon-brand::before   { background: var(--brand); }
.ribbon-accent::before  { background: var(--accent); }

/* ---------- Focus visible ---------------------------------- */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

/* ---------- ButtonGroup ------------------------------------- */
.btn-group { display: inline-flex; align-items: stretch; }
.btn-group-joined { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.btn-group-joined > * { border-radius: 0 !important; border: 0 !important; }
.btn-group-joined > * + * { border-inline-start: 1px solid var(--border-strong) !important; }
.btn-group-spaced { gap: 8px; }

/* ---------- Tooltip ----------------------------------------- */
.tooltip-wrap { display: inline-flex; }
.tooltip-floater {
  position: fixed; z-index: 9999; pointer-events: none;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.95); color: #fff;
  font-size: 12px; line-height: 1.4; padding: 4px 8px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  white-space: nowrap; max-width: 240px;
}

/* ---------- Toast ------------------------------------------- */
.toast-container {
  position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
  max-width: 26rem;
}
.toast-item {
  pointer-events: auto; border-radius: 8px;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -4px rgba(0,0,0,0.10);
  padding: 12px 16px; font-size: 14px; font-weight: 500;
  cursor: pointer; overflow-wrap: break-word; color: #fff;
}
.toast-error   { background: var(--danger); }
.toast-success { background: var(--success); }
.toast-info    { background: var(--info); }
.toast-warn    { background: var(--warning); }
