/* ============================================
   Atelier CRM — Design System
   Editorial, warm, crafted.
============================================ */

:root {
  /* Color palette */
  --walnut-deep: #5a3e2b;
  --walnut: #8b5e3c;
  --walnut-light: #b8895a;
  --brass: #b8895a;
  --brass-bright: #d4a574;
  --sage: #8ba888;
  --forest: #3a5a40;
  --terracotta: #c56e4e;
  --burgundy: #8b3a3a;
  --oak: #9a7b4f;

  --cream: #f5eddc;
  --cream-deep: #ebdfc5;
  --paper: #fdfaf3;
  --ink: #231c13;
  --ink-soft: #3d342a;
  --ink-muted: #8b7e6a;
  --line: #d9ceb5;
  --line-soft: #e8dfc8;

  --shadow-sm: 0 1px 3px rgba(90, 62, 43, 0.08);
  --shadow-md: 0 4px 12px rgba(90, 62, 43, 0.12);
  --shadow-lg: 0 12px 32px rgba(90, 62, 43, 0.15);

  --serif: 'Fraunces', 'Times New Roman', serif;
  --sans: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ============ APP SHELL ============ */
.app-wrap {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--walnut);
  width: 32px; height: 32px;
  border: 1.5px solid var(--walnut);
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  font-family: var(--serif);
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: 0.05em;
}

/* Nav */
.nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-section {
  margin-bottom: 14px;
}

.nav-label {
  font-family: var(--mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  padding: 6px 12px;
  margin-bottom: 2px;
  font-weight: 500;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink-soft);
  transition: all 0.15s;
  position: relative;
}

.nav-item:hover {
  background: var(--cream);
  color: var(--ink);
}

.nav-item.active {
  background: var(--ink);
  color: var(--cream);
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 16px;
  background: var(--brass-bright);
  border-radius: 2px;
}

.nav-item svg { opacity: 0.7; flex-shrink: 0; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 6px;
  background: var(--cream);
  border-radius: 10px;
  color: var(--ink-muted);
}

.nav-item.active .nav-badge {
  background: var(--brass);
  color: var(--ink);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--line-soft);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--walnut);
  color: var(--cream);
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 12.5px; font-weight: 500; }
.user-role { font-size: 10.5px; color: var(--ink-muted); font-family: var(--serif); font-style: italic; }

.logout-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  transition: all 0.2s;
}
.logout-btn:hover { background: var(--cream); color: var(--burgundy); }

/* ============ MAIN AREA ============ */
.main-area {
  background: var(--cream);
  padding: 28px 36px;
  min-height: 100vh;
  position: relative;
}

/* Subtle paper texture */
.main-area::before {
  content: '';
  position: fixed;
  inset: 0;
  left: 240px;
  background:
    radial-gradient(circle at 1px 1px, rgba(90, 62, 43, 0.04) 1px, transparent 0);
  background-size: 20px 20px;
  pointer-events: none;
  z-index: 0;
}

.main-area > * { position: relative; z-index: 1; }

/* Page headers */
.page-header {
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
}

.page-title-wrap { flex: 1; }

.page-eyebrow {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--brass);
  margin-bottom: 6px;
  font-weight: 500;
}

.page-title {
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.1;
  margin-bottom: 6px;
}

.page-title em {
  font-style: italic;
  color: var(--walnut);
  font-weight: 300;
}

.page-subtitle {
  color: var(--ink-muted);
  font-size: 14px;
  font-family: var(--serif);
  font-style: italic;
  max-width: 600px;
}

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

/* ============ BUTTONS ============ */
.btn-primary, .btn-ghost, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--ink);
  color: var(--cream);
}
.btn-primary:hover { background: var(--walnut-deep); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-ghost {
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-ghost:hover { border-color: var(--walnut); background: var(--cream); }

.btn-danger {
  background: var(--burgundy);
  color: var(--cream);
}
.btn-danger:hover { background: #6e2e2e; }

.btn-primary svg, .btn-ghost svg, .btn-danger svg { width: 14px; height: 14px; }

/* ============ CARDS ============ */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

/* ============ STATS GRID ============ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 3px; height: 100%;
  background: var(--barcolor, var(--walnut));
}

.stat-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1;
}

.stat-delta {
  font-size: 11px;
  margin-top: 5px;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-muted);
}

/* ============ TABLES ============ */
.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  background: var(--cream);
  padding: 10px 14px;
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}

table.data td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}

table.data tbody tr:hover { background: var(--cream); cursor: pointer; }
table.data tbody tr:last-child td { border-bottom: none; }

.name-cell { font-weight: 500; }
.money { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ============ BADGES ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 10px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.badge-prospect { background: rgba(139, 126, 106, 0.15); color: var(--ink-muted); }
.badge-qualified, .badge-lead { background: rgba(58, 90, 64, 0.12); color: var(--forest); }
.badge-proposal, .badge-sent { background: rgba(184, 137, 90, 0.18); color: var(--walnut); }
.badge-negotiation, .badge-partial { background: rgba(197, 110, 78, 0.12); color: var(--terracotta); }
.badge-won, .badge-paid, .badge-accepted, .badge-completed, .badge-received, .badge-customer { background: rgba(58, 90, 64, 0.15); color: var(--forest); }
.badge-lost, .badge-overdue, .badge-cancelled, .badge-void { background: rgba(139, 58, 58, 0.12); color: var(--burgundy); }
.badge-draft, .badge-pending { background: var(--cream-deep); color: var(--ink-muted); }
.badge-transit { background: rgba(184, 137, 90, 0.18); color: var(--walnut); }
.badge-active, .badge-inactive { background: var(--cream-deep); color: var(--ink-muted); }

/* ============ FORMS ============ */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (max-width: 700px) { .form-grid-2 { grid-template-columns: 1fr; } }

.form-field { display: flex; flex-direction: column; gap: 5px; }

.form-field label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  font-weight: 500;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: 13px;
  transition: border-color 0.2s;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--walnut);
  background: #fff;
}

.form-field textarea { resize: vertical; min-height: 70px; }

/* ============ MODALS ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 28, 19, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.active { display: flex; }

.modal {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.modal-title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.modal-title em {
  font-style: italic;
  color: var(--walnut);
  font-weight: 300;
}

.icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--cream); color: var(--ink); }

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--cream);
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: var(--cream);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all 0.3s;
  max-width: 340px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ============ LOGIN ============ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--cream) 0%, var(--paper) 100%);
  padding: 20px;
}

.login-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand .brand-mark {
  width: 56px; height: 56px;
  font-size: 36px;
  margin: 0 auto 14px;
}

.login-brand h1 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.login-brand p {
  color: var(--ink-muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  margin-top: 4px;
}

.login-error {
  padding: 10px 14px;
  background: rgba(139, 58, 58, 0.08);
  border: 1px solid rgba(139, 58, 58, 0.2);
  color: var(--burgundy);
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}

/* ============ PIPELINE KANBAN ============ */
.kanban {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  min-height: 500px;
}

.kanban-col {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

.kanban-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
  background: var(--cream);
  border-radius: var(--radius) var(--radius) 0 0;
}

.kanban-cards {
  padding: 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px;
}

.kanban-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: grab;
  transition: all 0.2s;
}

.kanban-card:hover { box-shadow: var(--shadow-sm); border-color: var(--walnut); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.5; }

.kanban-card-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.kanban-card-client { font-size: 11px; color: var(--ink-muted); font-family: var(--serif); font-style: italic; }
.kanban-card-value {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--walnut);
  font-weight: 500;
}

@media (max-width: 1100px) {
  .kanban { grid-template-columns: 1fr 1fr; }
}

/* ============ UTILITIES ============ */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-muted);
  font-family: var(--serif);
  font-style: italic;
}

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.grow { flex: 1; }
.text-muted { color: var(--ink-muted); }
.text-mono { font-family: var(--mono); }
.text-serif { font-family: var(--serif); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
