@import "@fontsource-variable/inter";
@import "tailwindcss";

@theme {
  --font-sans: "Inter Variable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --color-canvas: #f4f4f7;
  --color-odoo: #714b67;
  --color-odoo-dark: #5b3c53;
  --color-odoo-soft: #f4eef2;
  --color-line: #e3e6ea;
  --shadow-card: 0 1px 1px rgb(17 24 39 / 0.03);
  --shadow-pop: 0 10px 30px -12px rgb(17 24 39 / 0.3), 0 0 0 1px rgb(17 24 39 / 0.06);
}

@layer base {
  html {
    scrollbar-gutter: stable;
  }
  body {
    @apply bg-canvas text-slate-700 antialiased;
    font-size: 13px;
  }
  ::selection {
    @apply bg-odoo/20 text-odoo-dark;
  }
  input,
  select,
  textarea,
  button {
    font: inherit;
  }
}

@layer components {
  /* ---------- Buttons ---------- */
  .btn {
    @apply inline-flex h-8 cursor-pointer items-center justify-center gap-1.5 rounded border border-transparent px-3 text-[13px] font-medium whitespace-nowrap transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-odoo/30 focus-visible:ring-offset-1 disabled:pointer-events-none disabled:opacity-50;
  }
  .btn-primary {
    @apply border-odoo bg-odoo text-white hover:border-odoo-dark hover:bg-odoo-dark focus-visible:ring-odoo/40;
  }
  .btn-secondary {
    @apply border-line bg-white text-slate-600 hover:bg-slate-50 hover:text-slate-800 focus-visible:ring-slate-300;
  }
  .btn-danger {
    @apply border-rose-600 bg-rose-600 text-white hover:border-rose-700 hover:bg-rose-700;
  }
  .btn-ghost {
    @apply text-odoo hover:bg-odoo-soft focus-visible:ring-odoo/30;
  }
  .btn-sm {
    @apply h-7 gap-1 rounded px-2.5 text-[12px];
  }
  .icon-btn {
    @apply inline-flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded text-slate-400 transition-colors hover:bg-slate-100 hover:text-slate-700 focus:outline-none focus-visible:ring-2 focus-visible:ring-odoo/30;
  }

  /* ---------- Form controls ---------- */
  .input {
    @apply block w-full rounded border border-[#d5d9e0] bg-white px-2.5 py-1.5 text-[13px] leading-5 text-slate-800 outline-none transition placeholder:text-slate-400 focus:border-odoo focus:ring-2 focus:ring-odoo/15;
  }
  select.input {
    @apply cursor-pointer appearance-none pr-8;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 14px 14px;
  }
  .input-sm {
    @apply px-2 py-1 text-[12px];
  }
  .label {
    @apply mb-1 block text-[12px] font-medium text-slate-600;
  }
  .hint {
    @apply mt-1 text-[12px] text-slate-400;
  }
  .field-error {
    @apply mt-1 flex items-center gap-1 text-[12px] font-medium text-rose-600;
  }
  .o-check {
    @apply h-3.5 w-3.5 cursor-pointer rounded-[3px] border-slate-300 accent-odoo;
  }

  /* ---------- Surfaces ---------- */
  .card {
    @apply rounded-md border border-line bg-white;
  }
  .card-header {
    @apply flex items-center justify-between gap-3 border-b border-line px-4 py-2.5;
  }
  .sheet {
    @apply rounded-md border border-line bg-white;
  }
  .sheet-header {
    @apply flex flex-wrap items-start justify-between gap-4 border-b border-line px-4 py-4 sm:px-6;
  }
  .sheet-body {
    @apply px-4 py-4 sm:px-6 sm:py-5;
  }
  .filter-bar {
    @apply flex flex-col gap-2 rounded-md border border-line bg-white p-2.5 lg:flex-row lg:items-center;
  }
  .section-label {
    @apply text-[11px] font-semibold tracking-[0.08em] text-slate-400 uppercase;
  }
  .smart-btn {
    @apply flex min-h-12 min-w-28 items-center gap-2.5 rounded border border-line bg-white px-2.5 py-1.5 text-left transition-colors hover:border-odoo/40 hover:bg-odoo-soft/40;
  }
  .smart-btn-icon {
    @apply flex h-7 w-7 shrink-0 items-center justify-center rounded bg-odoo-soft text-odoo;
  }
  .smart-btn-body {
    @apply flex min-w-0 flex-col leading-tight;
  }
  .smart-btn-value {
    @apply truncate text-[13.5px] font-semibold text-slate-900;
  }
  .smart-btn-label {
    @apply truncate text-[11px] text-slate-500;
  }
  .empty-state {
    @apply flex flex-col items-center px-6 py-14 text-center;
  }

  /* ---------- Badges ---------- */
  .badge {
    @apply inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium whitespace-nowrap;
  }
  .badge-dot {
    @apply h-1.5 w-1.5 rounded-full bg-current;
  }

  /* ---------- Tables ---------- */
  .th {
    @apply px-2 py-2 text-left text-[11px] font-semibold tracking-[0.04em] text-slate-500 uppercase sm:px-3;
  }
  .td {
    @apply px-2 py-2.5 align-middle text-[13px] text-slate-600 sm:px-3;
  }
  .list-row {
    @apply transition-colors hover:bg-[#f8f5f7];
  }

  /* ---------- App shell ---------- */
  .topbar {
    @apply sticky top-0 z-40 bg-odoo text-white;
    box-shadow: 0 1px 0 rgb(0 0 0 / 0.14);
  }
  .topbar-link {
    @apply inline-flex h-12 shrink-0 items-center gap-1.5 px-2.5 text-[13px] font-medium text-white/75 transition-colors hover:bg-white/10 hover:text-white;
  }
  .topbar-link-active {
    @apply bg-black/20 text-white;
  }
  .topbar-icon {
    @apply inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded text-white/80 transition-colors hover:bg-white/10 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-white/40;
  }
  .topbar-search {
    @apply h-8 w-full rounded border border-white/15 bg-black/15 pr-3 pl-8 text-[13px] text-white outline-none transition placeholder:text-white/50 focus:border-white/30 focus:bg-black/25;
  }
  .control-panel {
    @apply border-b border-line bg-white;
  }
  .control-panel-inner {
    @apply mx-auto flex min-h-11 w-full max-w-[1600px] items-center gap-3 px-4 py-1.5 sm:px-6;
  }
  .breadcrumb {
    @apply flex min-w-0 items-center gap-1.5 text-[13px];
  }
  .breadcrumb-link {
    @apply shrink-0 text-slate-500 transition-colors hover:text-odoo;
  }
  .breadcrumb-current {
    @apply truncate font-medium text-slate-800;
  }
  .breadcrumb-sep {
    @apply shrink-0 text-slate-300;
  }
  .view-shell {
    @apply mx-auto w-full max-w-[1600px] px-4 py-4 sm:px-6;
  }

  /* ---------- Deal statusbar ---------- */
  .statusbar {
    @apply flex w-max items-center;
  }
  .statusbar-step {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    height: 30px;
    margin-left: -4px;
    padding: 0 1rem 0 1.15rem;
    background: #eef0f3;
    color: #475569;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 50%, calc(100% - 7px) 100%, 0 100%, 8px 50%);
    transition:
      background-color 0.15s,
      color 0.15s;
  }
  .statusbar-step:first-child {
    margin-left: 0;
    padding-left: 0.85rem;
    border-radius: 3px 0 0 3px;
    clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 50%, calc(100% - 7px) 100%, 0 100%);
  }
  .statusbar-step:last-child {
    padding-right: 0.9rem;
    border-radius: 0 3px 3px 0;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 8px 50%);
  }
  .statusbar-step:hover {
    background: #e3e6ea;
    color: #1f2937;
  }
  .statusbar-step-active,
  .statusbar-step-active:hover {
    background: var(--color-odoo);
    color: #fff;
  }

  /* ---------- Printable documents ---------- */
  .doc-body {
    background: #eceef1;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .doc-shell {
    padding: 20px 10px 48px;
  }
  .doc-sheet {
    width: 100%;
    max-width: 210mm;
    margin: 0 auto;
    padding: clamp(22px, 5vw, 56px);
    background: #fff;
    box-shadow:
      0 1px 2px rgb(17 24 39 / 0.06),
      0 18px 40px -28px rgb(17 24 39 / 0.45);
  }
  .doc-caption {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
  }
  .doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }
  .doc-table thead th {
    padding: 7px 8px;
    border-bottom: 1px solid var(--color-line);
    background: #f5f5f8;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
  }
  .doc-table tbody td {
    padding: 8px;
    border-bottom: 1px solid #eef0f3;
    vertical-align: top;
    color: #334155;
  }
  .doc-table .num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }
  .doc-table .doc-section-row td {
    padding: 7px 8px;
    background: #f8f8fa;
    font-size: 11.5px;
    font-weight: 600;
    color: #334155;
  }
  .doc-table .doc-note-row td {
    padding: 7px 8px;
    font-size: 11.5px;
    font-style: italic;
    color: #64748b;
  }

  /* ---------- Bundled report ---------- */
  .report-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 210mm;
    margin: 0 auto;
  }
  .report-sheet > .doc-sheet {
    max-width: none;
  }

  /* ---------- Kanban ---------- */
  .kanban-column {
    @apply flex w-[288px] shrink-0 flex-col rounded-md border border-line bg-[#f1f2f5];
  }
  .kanban-cards {
    @apply flex min-h-24 flex-1 flex-col gap-2 overflow-y-auto p-2;
  }
  .deal-card {
    @apply cursor-grab rounded border border-line bg-white p-3 transition hover:border-odoo/40 active:cursor-grabbing;
  }
  .quotation-card {
    @apply rounded border border-line bg-white p-3 transition hover:border-odoo/40 hover:shadow-sm;
  }
}

@layer utilities {
  .scrollbar-thin {
    scrollbar-width: thin;
    scrollbar-color: rgb(203 213 225) transparent;
  }
  .animate-fade-up {
    animation: fade-up 0.25s ease-out both;
  }
  @keyframes fade-up {
    from {
      opacity: 0;
      transform: translateY(4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

[x-cloak] {
  display: none !important;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 150ms ease;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}
.htmx-swapping {
  opacity: 0;
  transition: opacity 150ms ease;
}
.htmx-added {
  opacity: 1;
}

.sortable-ghost {
  opacity: 0.35;
}
.sortable-chosen {
  box-shadow: var(--shadow-pop);
  transform: rotate(1deg);
}
.sortable-drag {
  opacity: 0.95;
}

.view-section {
  view-transition-name: none;
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }
  html,
  body {
    background: #fff !important;
  }
  .no-print {
    display: none !important;
  }
  .doc-shell {
    padding: 0;
  }
  .doc-sheet {
    width: 210mm;
    min-height: 297mm;
    max-width: none;
    padding: 14mm 16mm;
    box-shadow: none;
  }
  .report-stack {
    gap: 0;
    max-width: none;
  }
  .report-sheet {
    break-before: page;
    page-break-before: always;
  }
  .report-sheet > .doc-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
  }
  .doc-table thead th {
    background: #f5f5f8 !important;
  }
}
