/* =============================================================================
   Contrak — Design System
   -----------------------------------------------------------------------------
   Self-contained. No Bootstrap/jQuery/Select2 — everything below (grid,
   forms, multi-select, tabs, modal, kanban) is written from scratch so the
   codebase has zero third-party runtime dependencies to vendor or update.
   System font stack is used deliberately (no webfont files to manage on an
   internal Bitnami box with no outbound access).
   ========================================================================== */

:root {
  /* Palette */
  --ink: #16202B;
  --ink-soft: #57667A;
  --ink-faint: #8A96A3;
  --paper: #F5F6F8;
  --surface: #FFFFFF;
  --line: #E1E5EA;
  --line-strong: #C7CDD6;
  --accent: #1F3A5F;
  --accent-hover: #16293F;
  --accent-soft: #EAF0F7;
  --good: #2F7D5D;
  --good-soft: #E7F3EE;
  --warn: #B8860B;
  --warn-soft: #FBF3DF;
  --bad: #B3452C;
  --bad-soft: #FBEAE5;
  --neutral-soft: #EEF0F3;

  /* Type scale */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;

  /* Spacing / shape */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(22,32,43,0.06);
  --shadow-md: 0 4px 16px rgba(22,32,43,0.10);
  --sidebar-w: 240px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 0.5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.text-muted { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.mono { font-family: var(--font-mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* =============================================================================
   App shell
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--ink);
  color: #C9D3DE;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand img { height: 28px; width: auto; border-radius: 4px; background: #fff; padding: 2px; }
.sidebar-brand span { font-weight: 700; color: #fff; font-size: var(--fs-md); }
.sidebar-nav { padding: 0.75rem 0.5rem; overflow-y: auto; flex: 1; }
.sidebar-section-label {
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #6B7A8C; padding: 0.9rem 0.75rem 0.35rem;
}
.sidebar-link {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: #C9D3DE; font-size: var(--fs-sm); font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; color: #fff; }
.sidebar-link.active { background: var(--accent); color: #fff; }
.sidebar-link svg { flex-shrink: 0; opacity: 0.9; }
.sidebar-foot { padding: 0.85rem 1.1rem; border-top: 1px solid rgba(255,255,255,0.08); font-size: var(--fs-xs); color: #6B7A8C; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: var(--fs-md); }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; }
.user-chip {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: var(--fs-sm); color: var(--ink-soft);
}
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--fs-xs);
}
.content { padding: 1.25rem; flex: 1; }
.content-narrow { max-width: 640px; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; z-index: 40; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex !important; }
}

/* =============================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: inherit; font-size: var(--fs-sm); font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--neutral-soft); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--neutral-soft); color: var(--ink); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: var(--fs-xs); }
.btn-icon { padding: 0.4rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: inline-flex; gap: 0.4rem; flex-wrap: wrap; }

/* =============================================================================
   Cards / panels
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  flex-wrap: wrap;
}
.card-body { padding: 1.1rem; }
.card-footer { padding: 0.8rem 1.1rem; border-top: 1px solid var(--line); }

.tiles-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem 1.1rem; border-left: 4px solid var(--accent);
}
.tile .tile-count { font-size: 1.6rem; font-weight: 700; }
.tile .tile-label { font-size: var(--fs-xs); color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }

/* =============================================================================
   Forms — multi-column layout support
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 0.9rem 1.25rem; }
.form-grid.cols-1 { --cols: 1; }
.form-grid.cols-3 { --cols: 3; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr !important; } }

.form-field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.form-field.span-2 { grid-column: span 2; }
.form-field.span-3 { grid-column: span 3; }
.form-field.span-full { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-field.span-2, .form-field.span-3, .form-field.span-full { grid-column: auto; } }

label, .form-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.form-hint { font-size: var(--fs-xs); color: var(--ink-soft); }
.form-error { font-size: var(--fs-xs); color: var(--bad); }
.required-mark { color: var(--bad); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=url], input[type=search],
select, textarea {
  font-family: inherit; font-size: var(--fs-base); color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  width: 100%;
}
textarea { resize: vertical; min-height: 5rem; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input.field-invalid, select.field-invalid, textarea.field-invalid { border-color: var(--bad); }
.input-prefix-group { display: flex; }
.input-prefix-group .prefix {
  display: flex; align-items: center; padding: 0 0.6rem;
  background: var(--neutral-soft); border: 1px solid var(--line-strong); border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); font-size: var(--fs-sm); color: var(--ink-soft); font-weight: 600;
}
.input-prefix-group input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input[type=checkbox] { width: 16px; height: 16px; }
fieldset { border: none; padding: 0; margin: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 0.5rem; }
.form-section-title { font-size: var(--fs-md); font-weight: 700; margin: 1.5rem 0 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.form-section-title:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.form-actions { display: flex; gap: 0.6rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }

/* Custom multi-select (see assets/js/multiselect.js) */
.msel { position: relative; }
.msel-control {
  display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem; min-height: 2.3rem; cursor: text; background: var(--surface);
}
.msel-control:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.msel-tag {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 0.15rem 0.5rem; font-size: var(--fs-xs); font-weight: 600;
}
.msel-tag button { background: none; border: none; cursor: pointer; color: var(--accent); font-size: 0.9rem; line-height: 1; padding: 0; }
.msel-input { flex: 1; min-width: 80px; border: none; outline: none; font-size: var(--fs-sm); padding: 0.15rem; }
.msel-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 220px; overflow-y: auto; display: none;
}
.msel-dropdown.open { display: block; }
.msel-option { padding: 0.5rem 0.7rem; font-size: var(--fs-sm); cursor: pointer; }
.msel-option:hover, .msel-option.highlighted { background: var(--accent-soft); }
.msel-option.selected { color: var(--ink-faint); }
.msel-empty { padding: 0.5rem 0.7rem; font-size: var(--fs-xs); color: var(--ink-faint); }

/* =============================================================================
   Tables / listings
   ========================================================================== */
.table-toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; justify-content: space-between; }
.table-filters { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.table-filters input, .table-filters select { width: auto; min-width: 140px; }
.data-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data-table th {
  text-align: left; padding: 0.6rem 0.9rem; background: var(--paper);
  border-bottom: 1px solid var(--line); color: var(--ink-soft); font-weight: 600; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
table.data-table td { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--paper); }
th.sortable a { color: inherit; display: inline-flex; align-items: center; gap: 0.25rem; }
th.sortable a:hover { text-decoration: none; color: var(--ink); }
.row-actions { display: flex; gap: 0.4rem; }

.pagination { display: flex; align-items: center; gap: 0.4rem; justify-content: flex-end; margin-top: 1rem; font-size: var(--fs-sm); }
.pagination a, .pagination span {
  padding: 0.35rem 0.65rem; border-radius: var(--radius-sm); border: 1px solid var(--line);
  color: var(--ink); min-width: 2rem; text-align: center;
}
.pagination a:hover { background: var(--neutral-soft); text-decoration: none; }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* =============================================================================
   Badges / status pills — the vocabulary reused across lists, detail, kanban
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: var(--fs-xs); font-weight: 700; padding: 0.2rem 0.55rem;
  border-radius: 999px; background: var(--neutral-soft); color: var(--ink-soft);
  white-space: nowrap;
}
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }
.pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* =============================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; }
.tab-link {
  padding: 0.6rem 0.9rem; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-link:hover { color: var(--ink); text-decoration: none; }
.tab-link.active { color: var(--accent); border-bottom-color: var(--accent); }

/* =============================================================================
   Kanban board (Deals) — the app's signature view
   ========================================================================== */
.kanban-scroll { overflow-x: auto; padding-bottom: 0.5rem; }
.kanban-board { display: flex; gap: 0.9rem; align-items: flex-start; min-height: 60vh; }
.kanban-col {
  flex: 0 0 270px; background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 220px);
}
.kanban-col-head {
  padding: 0.7rem 0.85rem; font-weight: 700; font-size: var(--fs-sm);
  border-bottom: 3px solid var(--accent); border-radius: var(--radius) var(--radius) 0 0;
  display: flex; justify-content: space-between; align-items: center; background: var(--surface);
}
.kanban-col-head .count { font-weight: 600; color: var(--ink-soft); background: var(--neutral-soft); border-radius: 999px; padding: 0.1rem 0.5rem; font-size: var(--fs-xs); }
.kanban-col-body { padding: 0.6rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 0.6rem; }
.kanban-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem; box-shadow: var(--shadow-sm); cursor: grab;
}
.kanban-card:hover { border-color: var(--line-strong); }
.kanban-card.dragging { opacity: 0.5; }
.kanban-card .kc-title { font-weight: 700; font-size: var(--fs-sm); margin-bottom: 0.3rem; }
.kanban-card .kc-meta { font-size: var(--fs-xs); color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.kanban-col.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* =============================================================================
   Toasts / flash messages
   ========================================================================== */
.flash-stack { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; max-width: 360px; }
.flash {
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm); font-size: var(--fs-sm);
  box-shadow: var(--shadow-md); border: 1px solid transparent; background: var(--surface);
  display: flex; justify-content: space-between; gap: 0.6rem; align-items: flex-start;
}
.flash-success { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.flash-error { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.flash-info { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.flash-warning { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.flash button { background: none; border: none; cursor: pointer; color: inherit; font-size: 1rem; line-height: 1; }

/* =============================================================================
   Modal
   ========================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,32,43,0.45); z-index: 60;
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
}
.modal-header { padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1.2rem; }
.modal-footer { padding: 1rem 1.2rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 0.6rem; }

/* =============================================================================
   Empty states / misc
   ========================================================================== */
.empty-state { padding: 2.5rem 1.5rem; text-align: center; color: var(--ink-soft); }
.empty-state svg { margin-bottom: 0.75rem; opacity: 0.5; }
.divider { height: 1px; background: var(--line); border: none; margin: 1.25rem 0; }
.sidebar-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--ink); }

/* =============================================================================
   Login page
   ========================================================================== */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--paper); padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 2rem; }
.login-card .sidebar-brand { border: none; padding: 0 0 1.5rem; justify-content: center; }
.login-card .sidebar-brand span { color: var(--ink); }
.login-card .sidebar-brand img { height: 36px; }
.login-divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.25rem 0; color: var(--ink-faint); font-size: var(--fs-xs); }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* =============================================================================
   Notes stream (deal notes)
   ========================================================================== */
.note-item { border-bottom: 1px solid var(--line); padding: 0.9rem 0; }
.note-item:last-child { border-bottom: none; }
.note-meta { font-size: var(--fs-xs); color: var(--ink-soft); margin-bottom: 0.3rem; display: flex; gap: 0.5rem; align-items: center; }
.note-content { font-size: var(--fs-sm); }
.note-content p:last-child { margin-bottom: 0; }

/* Rich text editor toolbar (deal notes) */
.rte-toolbar { display: flex; gap: 0.25rem; border: 1px solid var(--line-strong); border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; padding: 0.35rem; background: var(--paper); flex-wrap: wrap; }
.rte-toolbar button { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; width: 28px; height: 28px; cursor: pointer; font-size: var(--fs-sm); font-weight: 700; color: var(--ink); }
.rte-toolbar button:hover { background: var(--neutral-soft); }
.rte-editable { border: 1px solid var(--line-strong); border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 0.6rem 0.75rem; min-height: 6rem; font-size: var(--fs-sm); }
.rte-editable:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* File manager (deal documents) */
.folder-list { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1rem; }
.folder-chip { display: flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.8rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); font-size: var(--fs-sm); font-weight: 600; }
.folder-chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--ink-soft); font-size: var(--fs-sm); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
