/* ==========================================================================
   Forato CRM (Python port) — visual clone of the original design system.
   Tokens ported 1:1 from the original src/styles.css (Tailwind v4 @theme +
   shadcn/ui). No Tailwind/Radix here — plain CSS custom properties + plain
   selectors, same values, same names where practical, so the two apps stay
   visually recognizable as the same product. See docs/PYTHON_PORT.md.
   ========================================================================== */

:root {
  --radius: 0.9rem;

  --brand: #FFC300;
  --brand-strong: #D4AF37;
  --brand-master: #DC2626;
  --brand-soft: rgba(255, 195, 0, .10);
  --brand-soft-strong: rgba(255, 195, 0, .18);
  --brand-text: #B8860B;

  --bg-deep: #E8EEEA;
  --panel: #FFFFFF;
  --panel-2: #F2F6F3;
  --hairline: rgba(6, 22, 14, .11);
  --hairline-strong: rgba(6, 22, 14, .16);

  --surface: var(--panel);
  --sidebar-bg: #FFFFFF;

  --background: var(--bg-deep);
  --foreground: #0A1510;
  --card: var(--panel);
  --card-foreground: #0A1510;

  --primary: var(--brand);
  --primary-foreground: #3A2E00;
  --secondary: #E6EEE9;
  --secondary-foreground: #0A1510;
  --muted: #EFF3F0;
  --muted-foreground: #3C584B;
  --accent: #E6EEE9;
  --accent-foreground: #0A1510;
  --destructive: #DC2626;
  --destructive-foreground: #FFFFFF;
  --border: var(--hairline);
  --input: rgba(6, 22, 14, .13);
  --ring: var(--brand);

  --shadow-card: 0 1px 3px rgba(6, 22, 14, .07), 0 1px 2px rgba(6, 22, 14, .04);
  --shadow-glow: 0 0 0 1px rgba(255, 195, 0, .18), 0 8px 24px -10px rgba(255, 195, 0, .30);

  --page-gradient:
    radial-gradient(900px 500px at 100% -10%, rgba(255, 195, 0, .06), transparent 60%),
    radial-gradient(700px 400px at -10% 10%, rgba(255, 195, 0, .05), transparent 60%),
    var(--bg-deep);

  --font-sans: "Montserrat", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;

  --brand-text: #E6C46A;

  --bg-deep: #081410;
  --panel: #101D16;
  --panel-2: #16271E;
  --hairline: rgba(255, 255, 255, .11);
  --hairline-strong: rgba(255, 255, 255, .18);

  --sidebar-bg: #0B1410;

  --background: var(--bg-deep);
  --foreground: #F1F9F4;
  --card: var(--panel);
  --card-foreground: #F1F9F4;

  --primary-foreground: #04140B;
  --secondary: #16271E;
  --secondary-foreground: #F1F9F4;
  --muted: #13211A;
  --muted-foreground: #B4CEC0;
  --accent: #16271E;
  --accent-foreground: #F1F9F4;
  --destructive: #FF5A5A;
  --destructive-foreground: #1B0606;
  --input: rgba(255, 255, 255, .12);

  --brand-soft: rgba(255, 195, 0, .14);
  --brand-soft-strong: rgba(255, 195, 0, .22);

  --shadow-card: 0 1px 0 rgba(255, 255, 255, .02) inset, 0 6px 18px -10px rgba(0, 0, 0, .5);
  --shadow-glow: 0 0 0 1px rgba(255, 195, 0, .20), 0 8px 28px -10px rgba(255, 195, 0, .30);

  --page-gradient:
    radial-gradient(1200px 600px at 85% -15%, rgba(255, 195, 0, .08), transparent 60%),
    radial-gradient(900px 500px at -10% 15%, rgba(255, 195, 0, .05), transparent 60%),
    var(--bg-deep);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page-gradient);
  background-attachment: fixed;
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3 { font-family: var(--font-sans); letter-spacing: -0.01em; margin: 0 0 4px; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 600; }
label, .label { font-size: 13.5px; font-weight: 600; }

/* --------------------------------------------------------------------
   App shell — sidebar + content, mirrors src/components/app-shell.tsx
   -------------------------------------------------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--hairline);
}

.sidebar__brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 0.75rem;
  display: grid;
  place-items: center;
  color: #FFFFFF;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: 0 4px 14px -4px rgba(255, 195, 0, .5);
}
.sidebar__brand.is-master .sidebar__brand-mark {
  background: linear-gradient(135deg, var(--brand-master), #F87171);
  box-shadow: 0 4px 14px -4px rgba(220, 38, 38, .5);
}

.sidebar__brand-text { min-width: 0; }
.sidebar__brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__brand-sub { font-size: 11.5px; color: var(--muted-foreground); margin-top: -1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-section-label {
  padding: 0 12px;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted-foreground);
  opacity: .8;
}

.nav-section { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 0.6rem;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--muted-foreground);
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { color: var(--foreground); background: var(--panel-2); }

.nav-link.is-active {
  color: var(--foreground);
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 1px var(--brand-soft-strong);
}
.nav-link.is-active svg { color: var(--brand-strong); }
.nav-link.is-active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
  box-shadow: 0 0 12px var(--brand);
}
.nav-link--master { color: var(--brand-master) !important; }
.nav-link--master:hover { background: rgba(220, 38, 38, .08); }

.nav-sep { height: 1px; background: var(--hairline); margin: 4px 4px; }

.sidebar__footer {
  padding: 12px;
  border-top: 1px solid var(--hairline);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 0.85rem;
  background: var(--panel-2);
  border: 1px solid var(--hairline);
}
.user-card__avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 999px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  color: var(--brand-text);
  background: var(--brand-soft);
  box-shadow: 0 0 0 1px var(--hairline-strong);
}
.user-card__name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card__role { font-size: 11px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card__logout {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 0.5rem;
  color: var(--muted-foreground);
}
.user-card__logout:hover { color: var(--foreground); background: var(--panel); }

/* Topbar over the main content area */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--hairline);
}
.status-pill__dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.status-pill--ok { color: #16A34A; }
.status-pill--warn { color: #F59E0B; }
.status-pill--off { color: #DC2626; }

.content {
  flex: 1;
  padding: 32px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  overflow-x: auto;
}

/* --------------------------------------------------------------------
   Cards / panels — mirrors src/components/ui/card.tsx + the `.panel`
   Tailwind @utility.
   -------------------------------------------------------------------- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--hairline);
  border-radius: 1rem;
  box-shadow: var(--shadow-card);
  padding: 20px;
}

.grid { display: grid; gap: 16px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.kpi-value {
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1;
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  margin-top: 8px;
}
.kpi-label { color: var(--muted-foreground); font-size: 13.5px; font-weight: 500; }

/* --------------------------------------------------------------------
   Buttons — mirrors src/components/ui/button.tsx variants
   -------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border-radius: 0.6rem;
  border: 1px solid var(--hairline);
  background: var(--panel);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, opacity .12s ease;
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--brand);
  color: var(--primary-foreground);
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
.btn--primary:hover { background: var(--brand-strong); }

.btn--danger { background: var(--destructive); color: var(--destructive-foreground); border-color: transparent; }
.btn--danger:hover { opacity: .9; }

.btn--secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: transparent; }

/* --------------------------------------------------------------------
   Forms — mirrors src/components/ui/input.tsx
   -------------------------------------------------------------------- */

input, select, textarea {
  display: block;
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: 0.6rem;
  border: 1px solid var(--input);
  background: var(--panel);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 14px;
}
textarea { height: auto; padding: 10px 12px; min-height: 90px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--muted-foreground); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; margin-bottom: 6px; color: var(--muted-foreground); }

/* --------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--hairline); }
th { color: var(--muted-foreground); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }

/* --------------------------------------------------------------------
   Badges — mirrors src/components/ui/badge.tsx
   -------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 0.5rem;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--brand);
  color: var(--primary-foreground);
}
.badge--secondary { background: var(--secondary); color: var(--secondary-foreground); }
.badge--outline { background: transparent; border: 1px solid var(--hairline-strong); color: var(--foreground); }
.badge--danger { background: var(--destructive); color: var(--destructive-foreground); }

/* --------------------------------------------------------------------
   Flash messages
   -------------------------------------------------------------------- */

.flash-stack { position: fixed; top: 16px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.flash {
  padding: 12px 16px;
  border-radius: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  font-size: 13.5px;
}
.flash--error { border-color: var(--destructive); color: var(--destructive); }
.flash--success { border-color: var(--brand-strong); }
.flash--info { border-color: var(--hairline-strong); }

/* --------------------------------------------------------------------
   Kanban — mirrors src/features/crm/components/Kanban{Board,Column,Card}
   -------------------------------------------------------------------- */

.kanban { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 12px; }

.kanban-col {
  flex: 0 0 300px;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 1rem;
  padding: 16px;
  min-height: 480px;
}

.kanban-col__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14.5px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hairline);
}

.kanban-card {
  background: var(--panel-2);
  border: 1px solid var(--hairline);
  border-radius: 0.75rem;
  padding: 14px;
  margin-bottom: 10px;
  cursor: grab;
  transition: border-color .12s ease;
}
.kanban-card:hover { border-color: rgba(255, 195, 0, .35); }
.kanban-card__value { font-weight: 800; font-size: 14px; color: var(--brand-text); margin-top: 6px; }

/* --------------------------------------------------------------------
   Auth / marketing pages
   -------------------------------------------------------------------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: 380px; padding: 36px; }
.auth-logo {
  width: 52px; height: 52px;
  border-radius: 1rem;
  display: grid; place-items: center;
  margin: 0 auto 20px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: var(--shadow-glow);
}
.auth-logo svg { width: 26px; height: 26px; }

.landing-hero { max-width: 720px; margin: 100px auto; text-align: center; padding: 0 20px; }

/* --------------------------------------------------------------------
   Animated UI primitives — dialogs, dropdowns, toasts.
   Vanilla CSS/JS (see static/js/ui.js), styled to mirror the motion +
   look of the original app's Radix Dialog/DropdownMenu + sonner toasts
   (src/components/ui/{dialog,dropdown-menu}.tsx) without pulling in
   Radix/sonner themselves.
   -------------------------------------------------------------------- */

@keyframes ui-overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes ui-overlay-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes ui-modal-in { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes ui-modal-out { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(8px) scale(.96); } }
@keyframes ui-dropdown-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes ui-dropdown-out { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes ui-toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes ui-toast-out { from { opacity: 1; transform: translateX(0); max-height: 80px; margin-bottom: 8px; } to { opacity: 0; transform: translateX(24px); max-height: 0; margin-bottom: 0; } }

/* Modal / Dialog */

.ui-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(6, 22, 14, .45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: ui-overlay-in .16s ease-out;
}
[data-theme="dark"] .ui-overlay { background: rgba(0, 0, 0, .6); }
.ui-overlay.is-closing { animation: ui-overlay-out .14s ease-in forwards; }

.ui-modal {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--hairline);
  border-radius: 1rem;
  box-shadow: 0 20px 60px -15px rgba(0, 0, 0, .35);
  padding: 24px;
  animation: ui-modal-in .18s cubic-bezier(.16, 1, .3, 1);
}
.ui-overlay.is-closing .ui-modal { animation: ui-modal-out .14s ease-in forwards; }

.ui-modal__title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.ui-modal__desc { font-size: 13.5px; color: var(--muted-foreground); margin-bottom: 18px; }
.ui-modal__footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Dropdown menu */

.dropdown { position: relative; display: inline-block; }
.dropdown-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 0.5rem;
  color: var(--muted-foreground);
  background: transparent;
  border: none;
  cursor: pointer;
}
.dropdown-trigger:hover { color: var(--foreground); background: var(--panel-2); }
.dropdown-trigger svg { width: 16px; height: 16px; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 170px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 0.75rem;
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, .25);
  padding: 6px;
  z-index: 60;
  animation: ui-dropdown-in .12s cubic-bezier(.16, 1, .3, 1);
}
.dropdown-menu.is-closing { animation: ui-dropdown-out .1s ease-in forwards; }
.dropdown-menu[hidden] { display: none; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.dropdown-item:hover { background: var(--panel-2); }
.dropdown-item svg { width: 15px; height: 15px; flex-shrink: 0; color: var(--muted-foreground); }
.dropdown-item--danger { color: var(--destructive); }
.dropdown-item--danger svg { color: var(--destructive); }
.dropdown-item--danger:hover { background: rgba(220, 38, 38, .08); }

/* Toasts (JS-triggered — distinct from server-rendered .flash) */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1100;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--brand-strong);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .3);
  font-size: 13.5px;
  font-weight: 500;
  animation: ui-toast-in .18s cubic-bezier(.16, 1, .3, 1);
  overflow: hidden;
}
.toast.is-closing { animation: ui-toast-out .16s ease-in forwards; }
.toast--success { border-left-color: #16A34A; }
.toast--error { border-left-color: var(--destructive); color: var(--destructive); }
.toast--info { border-left-color: var(--brand); }
.toast__icon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.toast__close { margin-left: auto; background: none; border: none; color: var(--muted-foreground); cursor: pointer; padding: 0; line-height: 1; }

@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .content { padding: 16px; }
}
