/* =========================================================================
   Nusantara Rempah CRM — design tokens
   Palette drawn from the trade itself: ledger navy for structure, saffron
   and clove for the spices being sold, cardamom green for "won" states.
   ========================================================================= */
:root {
  --ink: #1c2733;
  --ink-soft: #384454;
  --paper: #f6f7f5;
  --paper-raised: #ffffff;
  --line: #e2e5e1;
  --line-strong: #c9cec7;
  --muted: #6b7480;

  --saffron: #c68a2e;
  --saffron-dark: #93641c;
  --saffron-tint: #faf1de;

  --clove: #8c3e2b;
  --clove-tint: #f6e7e2;

  --cardamom: #4c7a5e;
  --cardamom-tint: #e6efe9;

  --rose: #a3384a;
  --rose-tint: #f7e4e7;

  --font-display: "Fraunces", "Georgia", serif;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --shadow-card: 0 1px 2px rgba(28, 39, 51, 0.06), 0 6px 20px -8px rgba(28, 39, 51, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0 0 .35em; color: var(--ink); }
a { color: inherit; text-decoration: none; }
p { margin: 0 0 .75em; }

::selection { background: var(--saffron-tint); color: var(--clove-dark); }

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--ink);
  color: #dfe4ea;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar::-webkit-scrollbar {
  width: 5px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
}


.brand {
  padding: 22px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--saffron), var(--clove));
  font-family: var(--font-display); font-weight: 700; color: #1c2733; font-size: 16px;
  margin-bottom: 10px;
}
.brand-name { font-family: var(--font-display); font-size: 16px; color: #fff; line-height: 1.25; }
.brand-tag { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: #8f9aab; margin-top: 2px; }

.nav-group { padding: 14px 10px; }
.nav-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #6b7686; padding: 10px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-s);
  color: #c4cbd6; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: rgba(198,138,46,0.18); color: var(--saffron); }
.nav-icon { width: 16px; text-align: center; font-size: 14px; opacity: .9; }

.sidebar-footer {
  margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px; color: #8f9aab;
}
.sidebar-footer .user-name { color: #e7eaee; font-weight: 600; display:block; }
.sidebar-footer form { margin-top: 6px; }
.sidebar-footer button {
  background: none; border: none; color: #8f9aab; font-size: 12px; cursor: pointer; padding: 0;
}
.sidebar-footer button:hover { color: var(--saffron); text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; }
.topbar .crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }

.content { padding: 24px 28px 60px; }

/* ---------------------------------------------------------------- messages */
.messages { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 10px 14px; border-radius: var(--radius-s); font-size: 13.5px; border: 1px solid transparent; }
.msg.success { background: var(--cardamom-tint); color: #2e5b41; border-color: #c3ddcd; }
.msg.warning { background: var(--saffron-tint); color: var(--saffron-dark); border-color: #e6cfa0; }
.msg.error   { background: var(--rose-tint); color: var(--rose); border-color: #e6c2c8; }
.msg.info    { background: #e9eef5; color: #33475c; border-color: #cdd9e6; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 20px 22px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-header h2, .card-header h3 { margin: 0; font-size: 15.5px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 16px 18px; box-shadow: var(--shadow-card);
}
.stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.stat-value { font-family: var(--font-display); font-size: 26px; color: var(--ink); }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-card.accent-saffron { border-top: 3px solid var(--saffron); }
.stat-card.accent-clove { border-top: 3px solid var(--clove); }
.stat-card.accent-cardamom { border-top: 3px solid var(--cardamom); }
.stat-card.accent-rose { border-top: 3px solid var(--rose); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-body); font-weight: 600; font-size: 13px;
  padding: 8px 15px; border-radius: var(--radius-s); border: 1px solid transparent;
  cursor: pointer; line-height: 1.2;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #0f151d; }
.btn-saffron { background: var(--saffron); color: #241705; }
.btn-saffron:hover { background: var(--saffron-dark); color: #fff; }
.btn-outline { background: transparent; border-color: var(--line-strong); color: var(--ink-soft); }
.btn-outline:hover { border-color: var(--ink-soft); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { color: var(--ink); text-decoration: underline; }
.btn-danger { background: transparent; color: var(--rose); border-color: #e6c2c8; }
.btn-danger:hover { background: var(--rose-tint); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- forms */
.field-group { margin-bottom: 14px; }
.field-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field-input, .field-select, .field-textarea, select, input[type=text], input[type=email],
input[type=number], input[type=date], input[type=password], textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  font-family: var(--font-body); font-size: 13.5px; background: #fff; color: var(--ink);
}
.field-textarea { resize: vertical; }
.field-input:focus, .field-select:focus, .field-textarea:focus, select:focus, textarea:focus,
input:focus { outline: 2px solid var(--saffron); outline-offset: 1px; border-color: var(--saffron); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.helptext { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* Form Error & Required Indicators */
.required-star {
  color: var(--rose);
  font-weight: 700;
  margin-left: 3px;
}
.form-error-alert {
  background-color: var(--rose-tint);
  border: 1px solid #e6c2c8;
  color: var(--rose);
  padding: 12px 16px;
  border-radius: var(--radius-s);
  margin-bottom: 18px;
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-group.has-error .field-input,
.field-group.has-error .field-select,
.field-group.has-error .field-textarea,
.field-input.is-invalid,
.field-select.is-invalid,
.field-textarea.is-invalid,
select.is-invalid,
input.is-invalid,
textarea.is-invalid {
  border-color: var(--rose) !important;
  background-color: #fcf2f4 !important;
  box-shadow: 0 0 0 3px rgba(163, 56, 74, 0.15) !important;
}
.errorlist, .field-error {
  list-style: none;
  padding: 0;
  margin: 5px 0 0;
  color: var(--rose);
  font-size: 12px;
  font-weight: 600;
}
.errorlist li, .field-error {
  display: flex;
  align-items: center;
  gap: 4px;
}
.errorlist li::before, .field-error::before {
  content: "⚠️ ";
  font-size: 11px;
}

/* Product Chip / Badge Selector */
.product-chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: #fafaf8;
}
.product-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.product-chip:hover {
  border-color: var(--saffron);
  background: #fefcf8;
}
.product-chip.selected {
  border-color: var(--saffron);
  background: var(--saffron-tint);
  box-shadow: 0 0 0 1px var(--saffron);
}
.product-chip input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--saffron-dark);
  cursor: pointer;
  margin-top: 2px;
}
.product-chip-info {
  display: flex;
  flex-direction: column;
}
.product-chip-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.product-chip-category {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.product-search-box {
  margin-bottom: 8px;
  position: relative;
}


/* ---------------------------------------------------------------- table */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: #fafaf8;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fbfaf7; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 100px; white-space: nowrap;
}
.badge-new { background: #e9eef5; color: #33475c; }
.badge-sample { background: var(--saffron-tint); color: var(--saffron-dark); }
.badge-negotiation { background: #f0e6f5; color: #6b3a85; }
.badge-quotation { background: #dfeaf7; color: #245a8c; }
.badge-deal { background: var(--cardamom-tint); color: #2e5b41; }
.badge-lost { background: #eee; color: #888; text-decoration: line-through; }
.badge-draft { background: #eee; color: #666; }
.badge-sent { background: #dfeaf7; color: #245a8c; }
.badge-accepted { background: var(--cardamom-tint); color: #2e5b41; }
.badge-rejected { background: var(--rose-tint); color: var(--rose); }
.badge-unpaid { background: var(--saffron-tint); color: var(--saffron-dark); }
.badge-paid { background: var(--cardamom-tint); color: #2e5b41; }
.badge-overdue { background: var(--rose-tint); color: var(--rose); }
.badge-preparing { background: #eee; color: #666; }
.badge-shipped, .badge-in_transit { background: #dfeaf7; color: #245a8c; }
.badge-delivered, .badge-feedback_positive { background: var(--cardamom-tint); color: #2e5b41; }
.badge-feedback_negative, .badge-cancelled { background: var(--rose-tint); color: var(--rose); }
.badge-partial { background: var(--saffron-tint); color: var(--saffron-dark); }

.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.priority-high { background: var(--rose); }
.priority-medium { background: var(--saffron); }
.priority-low { background: var(--line-strong); }

/* ---------------------------------------------------------------- kanban */
.kanban { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kanban-col { width: 270px; flex-shrink: 0; }
.kanban-col-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 4px 6px 10px; border-bottom: 2px solid var(--line-strong);
  margin-bottom: 10px;
}
.kanban-col-head .count { font-size: 11.5px; color: var(--muted); }
.kanban-col-total { font-size: 11px; color: var(--muted); padding: 0 6px 8px; }
.kanban-card {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 12px 13px; margin-bottom: 10px; box-shadow: var(--shadow-card); display: block;
}
.kanban-card:hover { border-color: var(--saffron); }
.kanban-card .company { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.kanban-card .meta { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.kanban-card .value { font-family: var(--font-mono); font-size: 12.5px; color: var(--clove); font-weight: 600; }
.kanban-empty { font-size: 12px; color: var(--muted); text-align: center; padding: 18px 0; border: 1px dashed var(--line-strong); border-radius: var(--radius-m); }

/* ---------------------------------------------------------------- pipeline stepper */
.stepper { display: flex; align-items: center; gap: 0; margin: 4px 0 20px; flex-wrap: wrap; }
.step {
  display: flex; align-items: center; gap: 8px; padding: 7px 14px 7px 10px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); background: #eef0ec;
  border-right: 2px solid var(--paper);
}
.step:first-child { border-top-left-radius: 100px; border-bottom-left-radius: 100px; padding-left: 16px; }
.step:last-child { border-top-right-radius: 100px; border-bottom-right-radius: 100px; border-right: none; }
.step.done { background: var(--cardamom); color: #fff; }
.step.current { background: var(--saffron); color: #241705; }
.step-num { width: 18px; height: 18px; border-radius: 50%; background: rgba(255,255,255,0.35); display: flex; align-items: center; justify-content: center; font-size: 10.5px; }
.step:not(.done):not(.current) .step-num { background: rgba(0,0,0,0.08); }

/* ---------------------------------------------------------------- timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 18px 26px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-color: transparent; padding-bottom: 2px; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--saffron); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong);
}
.timeline .t-meta { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.timeline .t-body { font-size: 13px; color: var(--ink-soft); }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.active { color: var(--ink); border-bottom-color: var(--saffron); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------------------------------------------------------------- misc */
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); }
.empty-state {
  text-align: center; padding: 46px 20px; color: var(--muted);
  border: 1px dashed var(--line-strong); border-radius: var(--radius-l); background: #fbfaf7;
}
.empty-state .glyph { font-size: 30px; margin-bottom: 10px; display: block; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.search-input { max-width: 260px; }
.pill-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-nav a {
  font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 100px;
  border: 1px solid var(--line-strong); color: var(--ink-soft);
}
.pill-nav a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.qty-line { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.qty-line .field-group { flex: 1; margin-bottom: 0; }
.remove-row { color: var(--rose); font-size: 12px; cursor: pointer; padding-bottom: 9px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.total-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.total-line.grand { font-size: 17px; font-weight: 700; font-family: var(--font-display); border-top: 1px solid var(--line-strong); margin-top: 6px; padding-top: 12px; }

/* ---------------------------------------------------------------- login */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #2a3444, var(--ink));
}
.login-card { width: 360px; background: #fff; border-radius: var(--radius-l); padding: 30px 28px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-mark { width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, var(--saffron), var(--clove)); margin-bottom: 14px; }

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- mobile nav */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px; height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger span { display: block; width: 16px; height: 2px; background: var(--ink); margin: 0 auto; }
.topbar-left { display: flex; align-items: center; gap: 12px; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(20, 26, 34, 0.45);
  z-index: 15;
  opacity: 0;
  transition: opacity .2s;
}
.sidebar-overlay.visible { display: block; opacity: 1; }

@media (max-width: 860px) {
  .app-shell { display: block; }
  .hamburger { display: flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    z-index: 20;
    width: 250px;
    height: 100vh;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.35); }
  .main { width: 100%; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px 16px 50px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 21px; }
  .card-pad { padding: 16px; }
  .card-header { padding: 14px 16px; }
  .topbar-actions, .topbar > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
  .kanban-col { width: 78vw; }
  .form-actions { flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 17px; }
  .login-card { width: 92vw; padding: 24px 20px; }
  .btn { font-size: 12.5px; padding: 8px 12px; }
}

/* scrollable tables on small screens without breaking layout */
.card:has(table.data-table) { overflow-x: auto; }


/* ---------------------------------------------------------------- print */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .print-sheet { box-shadow: none; border: none; padding: 0; }
}
.stamp {
  display: inline-block; transform: rotate(-8deg); border: 3px solid var(--cardamom); color: var(--cardamom);
  font-family: var(--font-display); font-weight: 700; font-size: 22px; padding: 6px 18px;
  border-radius: 10px; letter-spacing: .08em; opacity: .85;
}
.stamp.unpaid { border-color: var(--rose); color: var(--rose); }
