/* ============================================================================
 * Indian Mercantile — UI replica of the Next.js/shadcn design system
 * Light + dark themes (html.dark), CSS custom properties, no dependencies.
 * ==========================================================================*/

/* ---------- design tokens ---------- */
:root {
  --radius: 10px;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --card-foreground: #0a0a0a;
  --popover: #ffffff;
  --popover-foreground: #0a0a0a;
  --primary: #171717;
  --primary-foreground: #fafafa;
  --primary-10: rgba(23, 23, 23, 0.1);
  --secondary: #f5f5f5;
  --secondary-foreground: #171717;
  --muted: #f5f5f5;
  --muted-foreground: #737373;
  --muted-foreground-60: rgba(115, 115, 115, 0.6);
  --muted-50: rgba(245, 245, 245, 0.55);
  --accent: #f5f5f5;
  --accent-foreground: #171717;
  --destructive: #dc2626;
  --destructive-foreground: #fafafa;
  --border: #e5e5e5;
  --input: #e5e5e5;
  --ring: #a3a3a3;
  --ring-alpha: rgba(163, 163, 163, 0.45);
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --overlay: rgba(0, 0, 0, 0.5);

  --emerald: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --teal-600: #0d9488;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --slate: #64748b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);

  --bg-badge-green: #d1fae5;  --fg-badge-green: #065f46;
  --bg-badge-amber: #fef3c7;  --fg-badge-amber: #92400e;
  --bg-badge-red:   #fee2e2;  --fg-badge-red:   #991b1b;
  --bg-badge-gray:  #f3f4f6;  --fg-badge-gray:  #374151;

  --chart-grid: rgba(115, 115, 115, 0.2);
  --scrollbar-thumb: rgba(0, 0, 0, 0.22);
}

html.dark {
  --background: #0a0a0a;
  --foreground: #fafafa;
  --card: #171717;
  --card-foreground: #fafafa;
  --popover: #171717;
  --popover-foreground: #fafafa;
  --primary: #e5e5e5;
  --primary-foreground: #0a0a0a;
  --primary-10: rgba(229, 229, 229, 0.12);
  --secondary: #262626;
  --secondary-foreground: #fafafa;
  --muted: #262626;
  --muted-foreground: #a3a3a3;
  --muted-foreground-60: rgba(163, 163, 163, 0.6);
  --muted-50: rgba(38, 38, 38, 0.55);
  --accent: #262626;
  --accent-foreground: #fafafa;
  --destructive: #ef4444;
  --destructive-foreground: #fafafa;
  --border: rgba(255, 255, 255, 0.12);
  --input: rgba(255, 255, 255, 0.16);
  --ring: #737373;
  --ring-alpha: rgba(115, 115, 115, 0.5);
  --topbar-bg: rgba(10, 10, 10, 0.85);
  --overlay: rgba(0, 0, 0, 0.65);

  --bg-badge-green: #052e16;  --fg-badge-green: #6ee7b7;
  --bg-badge-amber: #451a03;  --fg-badge-amber: #fcd34d;
  --bg-badge-red:   #450a0a;  --fg-badge-red:   #fca5a5;
  --bg-badge-gray:  #27272a;  --fg-badge-gray:  #d4d4d8;

  --chart-grid: rgba(163, 163, 163, 0.22);
  --scrollbar-thumb: rgba(255, 255, 255, 0.25);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3, h4, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--muted); padding: .1rem .35rem; border-radius: 5px; font-size: .85em;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
::selection { background: var(--primary-10); }

.custom-scrollbar::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- icons ---------- */
.ic { width: 16px; height: 16px; flex-shrink: 0; }
.ic-xs { width: 12px; height: 12px; flex-shrink: 0; }
.ic-lg { width: 20px; height: 20px; flex-shrink: 0; }
.ic-xl { width: 28px; height: 28px; flex-shrink: 0; }
.ic-spin { animation: ic-rotate 1s linear infinite; }
@keyframes ic-rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* icon swap: theme + sidebar collapse toggles */
html:not(.dark) .ic-sun { display: none; }
html.dark .ic-moon { display: none; }
html:not(.sb-collapsed) .ic-expand { display: none; }
html.sb-collapsed .ic-collapse { display: none; }

/* ============================================================================
 * App shell
 * ==========================================================================*/
.shell { min-height: 100vh; background: var(--background); color: var(--foreground); }

/* ---------- sidebar (fixed, collapsible) ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: 240px;
  display: flex; flex-direction: column;
  background: var(--background);
  border-right: 1px solid var(--border);
  transition: width .2s ease, transform .2s ease;
}
html.sb-collapsed .sidebar { width: 56px; }

.brand {
  display: flex; align-items: center; gap: 10px;
  height: 64px; padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}
html.sb-collapsed .brand {
  flex-direction: column; justify-content: center; gap: 6px;
  height: auto; min-height: 64px; padding: 8px 0;
}
.brand-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(to bottom right, var(--emerald), var(--teal-600));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm); flex-shrink: 0;
}
.brand-name {
  font-size: 14px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.brand-sub { font-size: 10px; color: var(--muted-foreground); line-height: 1.2; }
.brand-toggle {
  margin-left: auto; width: 32px; height: 32px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--muted-foreground);
  cursor: pointer; flex-shrink: 0;
}
.brand-toggle:hover { color: var(--foreground); background: var(--accent); }
html.sb-collapsed .brand-toggle { margin-left: 0; width: 26px; height: 26px; }

.sidebar-nav {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 16px;
  scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent;
}
.nav-group-label {
  margin: 0 0 4px 12px;
  font-size: 10px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted-foreground-60);
}
.nav-sep { width: 32px; height: 1px; background: var(--border); margin: 0 auto 8px; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px 12px;
  border-radius: 7px;
  font-size: 14px; font-weight: 500;
  color: var(--muted-foreground);
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item.active { background: var(--primary-10); color: var(--primary); font-weight: 500; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 50%;
  width: 4px; height: 20px; transform: translateY(-50%);
  border-radius: 0 999px 999px 0; background: var(--primary);
}
.nav-item .nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
html.sb-collapsed .nav-item { justify-content: center; padding: 10px 0; }
html.sb-collapsed .nav-item .nav-text { display: none; }
html.sb-collapsed .nav-group-label { display: none; }
html.sb-collapsed .nav-sep { display: block; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px 16px; flex-shrink: 0;
}
.sidebar-foot .signed-in { font-size: 10px; line-height: 1.5; color: var(--muted-foreground); }
.sidebar-foot .signed-in strong { color: var(--foreground); font-weight: 500; }
html.sb-collapsed .sidebar-foot { display: none; }

.nav-backdrop {
  position: fixed; inset: 0; z-index: 45;
  background: var(--overlay);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
@media (max-width: 767px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: translateX(0); }
  html.sb-collapsed .sidebar { width: 240px; }
  html.sb-collapsed .brand { flex-direction: row; height: 64px; padding: 0 12px; }
  html.sb-collapsed .nav-item { justify-content: flex-start; padding: 8px 12px; }
  html.sb-collapsed .nav-item .nav-text { display: block; }
  html.sb-collapsed .nav-group-label { display: block; }
  html.sb-collapsed .nav-sep { display: none; }
  html.sb-collapsed .sidebar-foot { display: block; }
  .brand-toggle { display: none; }
}
@media (min-width: 768px) {
  .nav-backdrop { display: none; }
  .menu-toggle { display: none !important; }
}

/* ---------- main column ---------- */
.main-col {
  display: flex; flex-direction: column; min-height: 100vh;
  padding-left: 240px;
  transition: padding-left .2s ease;
}
html.sb-collapsed .main-col { padding-left: 56px; }
@media (max-width: 767px) {
  .main-col, html.sb-collapsed .main-col { padding-left: 0; }
}

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: 64px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
@media (min-width: 768px) { .topbar { padding: 0 24px; } }
.menu-toggle {
  width: 36px; height: 36px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--muted-foreground); cursor: pointer;
}
.menu-toggle:hover { background: var(--accent); color: var(--foreground); }

/* global search */
.search-box { position: relative; flex: 1; min-width: 0; max-width: 448px; }
.search-box .search-ic {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); pointer-events: none;
}
.search-box .input { padding-left: 34px; padding-right: 34px; }
.search-spin {
  position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground);
}
.search-drop {
  position: absolute; left: 0; right: 0; top: calc(100% + 8px); z-index: 50;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--popover); color: var(--popover-foreground);
  box-shadow: var(--shadow-lg); overflow: hidden;
  display: none;
}
.search-drop.open { display: block; }
.search-drop-inner { max-height: 384px; overflow-y: auto; padding: 6px; }
.search-group-label {
  padding: 4px 8px 2px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted-foreground);
}
.search-hit {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border: none; background: none; border-radius: 7px;
  font-size: 14px; text-align: left; cursor: pointer; color: inherit;
}
.search-hit:hover { background: var(--accent); }
.search-hit .hit-label { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit .hit-sub { max-width: 45%; font-size: 12px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit .ic { color: var(--muted-foreground); }
.search-msg { padding: 20px 12px; text-align: center; font-size: 14px; color: var(--muted-foreground); }

/* topbar right */
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--muted-foreground); cursor: pointer;
}
.icon-btn:hover { background: var(--accent); color: var(--foreground); }
.icon-btn.sm { width: 32px; height: 32px; }

.avatar-btn {
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid var(--border);
  background: linear-gradient(to bottom right, var(--emerald), var(--teal-600));
  color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.avatar-btn:hover { filter: brightness(1.08); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  min-width: 240px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--popover); color: var(--popover-foreground);
  box-shadow: var(--shadow-md); padding: 5px;
  display: none;
}
.menu-wrap.open .menu { display: block; }
.menu-label { padding: 8px 10px; }
.menu-label .menu-name { font-size: 14px; font-weight: 600; }
.menu-label .menu-mail { font-size: 12px; color: var(--muted-foreground); }
.menu-sep { height: 1px; background: var(--border); margin: 4px -5px; }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: none; background: none; border-radius: 6px;
  font-size: 14px; text-align: left; cursor: pointer; color: inherit;
}
.menu-item:hover { background: var(--accent); }
.menu-item.danger { color: #dc2626; }
html.dark .menu-item.danger { color: #f87171; }
.menu-item.danger:hover { background: rgba(220, 38, 38, 0.08); }

.role-pill {
  display: inline-flex; align-items: center; margin-top: 5px;
  background: var(--bg-badge-green); color: var(--fg-badge-green);
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}

/* ---------- content + footer ---------- */
.content { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 24px; }
@media (min-width: 768px) { .content { padding: 24px; } }
.content > * { min-width: 0; }
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  text-align: center; font-size: 12px; color: var(--muted-foreground);
  line-height: 1.5;
}

/* ============================================================================
 * Page scaffolding
 * ==========================================================================*/
.page-head {
  display: flex; flex-direction: column; gap: 12px;
}
@media (min-width: 640px) {
  .page-head { flex-direction: row; align-items: center; justify-content: space-between; }
}
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.page-sub { font-size: 14px; color: var(--muted-foreground); margin-top: 2px; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* grids */
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi-grid { grid-template-columns: 1fr; }
@media (min-width: 640px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.grid-2xl { grid-template-columns: 1fr; }
@media (min-width: 1280px) { .grid-2xl { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ============================================================================
 * Cards
 * ==========================================================================*/
.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-click { transition: box-shadow .15s ease; cursor: pointer; }
.card-click:hover { box-shadow: var(--shadow-md); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 16px 16px 8px;
  flex-wrap: wrap;
}
.card-title { font-size: 16px; font-weight: 600; line-height: 1.4; margin: 0; }
.card-desc { font-size: 14px; color: var(--muted-foreground); margin-top: 2px; }
.card-body { padding: 16px; }
.card-body.p0 { padding: 0; }
.card-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* KPI stat card */
.kpi { padding: 16px; }
.kpi-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kpi-title {
  font-size: 12px; font-weight: 500; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .04em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-value {
  margin-top: 6px; font-size: 20px; font-weight: 700;
  font-variant-numeric: tabular-nums; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-sub { margin-top: 2px; font-size: 12px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-icon { color: var(--muted-foreground-60); }
.kpi-pos .kpi-value { color: var(--emerald-600); }
html.dark .kpi-pos .kpi-value { color: #34d399; }
.kpi-neg .kpi-value { color: #dc2626; }
html.dark .kpi-neg .kpi-value { color: #f87171; }
.kpi-warn .kpi-value { color: #d97706; }
html.dark .kpi-warn .kpi-value { color: #fbbf24; }
.kpi-primary .kpi-value { color: var(--primary); }

/* ============================================================================
 * Buttons
 * ==========================================================================*/
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--primary); color: var(--primary-foreground);
  font-size: 14px; font-weight: 500; line-height: 1.2;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .12s ease, color .12s ease, border-color .12s ease, box-shadow .12s ease;
  user-select: none;
}
.btn:hover { background: color-mix(in srgb, var(--primary) 90%, transparent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-outline {
  background: var(--background); color: var(--foreground);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--accent); }
.btn-danger { background: var(--destructive); color: var(--destructive-foreground); }
.btn-danger:hover { background: color-mix(in srgb, var(--destructive) 90%, transparent); }
.btn-danger-outline { background: transparent; color: var(--destructive); border-color: var(--border); }
.btn-danger-outline:hover { background: rgba(220, 38, 38, 0.08); }
.btn-emerald { background: var(--emerald-600); color: #fff; }
.btn-emerald:hover { background: var(--emerald-700); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; border-radius: var(--radius-sm); gap: 5px; }
.btn-icon { width: 36px; height: 36px; padding: 0; }
.btn-icon.btn-sm { width: 32px; height: 32px; padding: 0; }
.btn-icon.btn-xs { width: 26px; height: 26px; padding: 0; }
.btn-block { width: 100%; }

/* ============================================================================
 * Forms
 * ==========================================================================*/
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.label { font-size: 14px; font-weight: 500; line-height: 1.2; }
.label-xs { font-size: 12px; color: var(--muted-foreground); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 36px;
  padding: 0 12px;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  font: inherit; font-size: 14px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea.input { height: auto; min-height: 72px; padding: 8px 12px; resize: vertical; }
select.input { appearance: none; -webkit-appearance: none; background-image: none; padding-right: 30px;
  background: transparent; }
.input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--ring-alpha); }
.input:disabled { opacity: .55; cursor: not-allowed; }
.input::placeholder { color: var(--muted-foreground-60); }
select.input option { background: var(--popover); color: var(--popover-foreground); }
.hint { font-size: 12px; color: var(--muted-foreground); line-height: 1.45; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); gap: 14px 16px; }
.form-grid-wide { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--foreground); }
.req { color: var(--destructive); }

/* filter bar */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
}
.filters .field { min-width: 140px; }
.filters .input { height: 36px; }
.filters .w-date { max-width: 152px; }
.filters .w-fy { max-width: 150px; }

/* ============================================================================
 * Tables
 * ==========================================================================*/
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto; }
.table-wrap.collapsed-borders { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  padding: 10px 12px; text-align: left; vertical-align: middle;
  font-size: 12px; font-weight: 600; color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; background: transparent;
}
.table td {
  padding: 10px 12px; vertical-align: middle;
  border-bottom: 1px solid var(--border);
  color: var(--card-foreground);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .1s ease; }
.table tbody tr:hover { background: var(--muted-50); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.ctr, .table td.ctr { text-align: center; }
.table td.wrap { white-space: normal; min-width: 160px; }
.table tfoot td { font-weight: 700; border-top: 1px solid var(--border); background: var(--muted-50); }
.table .cell-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.table .cell-main { font-weight: 500; }
.table .cell-sub { font-size: 12px; color: var(--muted-foreground); }
.neg { color: #dc2626; }
html.dark .neg { color: #f87171; }
.pos { color: var(--emerald-600); }
html.dark .pos { color: #34d399; }
.clickable-row { cursor: pointer; }

/* ============================================================================
 * Badges / chips
 * ==========================================================================*/
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  white-space: nowrap; line-height: 1.5;
}
.badge-green { background: var(--bg-badge-green); color: var(--fg-badge-green); }
.badge-amber { background: var(--bg-badge-amber); color: var(--fg-badge-amber); }
.badge-red   { background: var(--bg-badge-red);   color: var(--fg-badge-red); }
.badge-gray  { background: var(--bg-badge-gray);  color: var(--fg-badge-gray); }
.badge-outline { background: transparent; border: 1px solid var(--border); color: var(--muted-foreground); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--secondary); color: var(--secondary-foreground);
  font-size: 12px; font-weight: 500;
}
.chip-emerald { background: var(--bg-badge-green); color: var(--fg-badge-green); }
.dot { width: 7px; height: 7px; border-radius: 999px; display: inline-block; }

/* ============================================================================
 * Tabs (shadcn pills)
 * ==========================================================================*/
.tabs {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--muted);
  border-radius: var(--radius-lg); padding: 4px;
  flex-wrap: wrap;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500; line-height: 1.5;
  color: var(--muted-foreground);
  border: none; background: transparent; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.tab:hover { color: var(--foreground); }
.tab.active {
  background: var(--background); color: var(--foreground);
  box-shadow: var(--shadow-sm);
}
html.dark .tab.active { background: #262626; box-shadow: 0 0 0 1px rgba(255,255,255,.06); }

/* ============================================================================
 * Dialogs (native <dialog>, shadcn look)
 * ==========================================================================*/
dialog.dlg {
  border: none; outline: none;
  padding: 0;
  width: calc(100vw - 32px);
  max-width: 512px;
  max-height: calc(100vh - 64px);
  background: var(--card); color: var(--card-foreground);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.dlg::backdrop { background: var(--overlay); }
dialog.dlg.sm { max-width: 425px; }
dialog.dlg.lg { max-width: 640px; }
dialog.dlg.xl { max-width: 800px; }
dialog.dlg.xxL { max-width: 1024px; }
dialog.dlg[open] { display: flex; flex-direction: column; }
dialog.dlg { margin: auto; }
.dlg-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 20px 20px 4px;
}
.dlg-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.dlg-desc { margin-top: 3px; font-size: 14px; color: var(--muted-foreground); }
.dlg-close {
  width: 30px; height: 30px; border-radius: 7px; border: none;
  background: transparent; color: var(--muted-foreground); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.dlg-close:hover { background: var(--accent); color: var(--foreground); }
.dlg-body { padding: 16px 20px; overflow-y: auto; }
.dlg-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 4px 20px 20px; flex-wrap: wrap;
}
.dlg-error {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid rgba(220, 38, 38, 0.25); background: rgba(220, 38, 38, 0.06);
  color: #b91c1c; border-radius: var(--radius-md);
  padding: 8px 12px; font-size: 13px; margin-bottom: 12px;
}
html.dark .dlg-error { color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); background: rgba(239, 68, 68, 0.08); }

/* ============================================================================
 * Alerts / callouts / banners
 * ==========================================================================*/
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  border-radius: var(--radius-lg);
  padding: 12px 16px; font-size: 12px; line-height: 1.6;
  border: 1px solid;
}
.alert-warn {
  border-color: #fde68a; background: #fffbeb; color: #92400e;
}
html.dark .alert-warn { border-color: #451a03; background: rgba(69, 26, 3, 0.4); color: #fcd34d; }
.alert-error {
  border-color: #fecaca; background: #fef2f2; color: #991b1b;
}
html.dark .alert-error { border-color: #450a0a; background: rgba(69, 10, 10, 0.5); color: #fca5a5; }
.alert-info {
  border-color: var(--border); background: var(--muted-50); color: var(--muted-foreground);
}
.alert a { text-decoration: underline; }

/* flash fallback (legacy .flash still styled as inline banner) */
.flash {
  padding: 10px 14px; border-radius: var(--radius-md);
  border: 1px solid; font-size: 14px; margin-bottom: 4px;
}
.flash.success { background: var(--bg-badge-green); border-color: rgba(5, 150, 105, .3); color: var(--fg-badge-green); }
.flash.error { background: var(--bg-badge-red); border-color: rgba(220, 38, 38, .3); color: var(--fg-badge-red); }

/* ============================================================================
 * Toasts (bottom-right)
 * ==========================================================================*/
.toast-wrap {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(384px, calc(100vw - 32px));
}
.toast {
  position: relative;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 14px 14px 14px 16px;
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .2s ease; }
.toast .toast-title { font-size: 14px; font-weight: 500; }
.toast .toast-desc { font-size: 13px; color: var(--muted-foreground); margin-top: 1px; }
.toast .toast-ic { margin-top: 1px; color: var(--emerald-600); }
html.dark .toast .toast-ic { color: #34d399; }
.toast.error .toast-ic { color: var(--destructive); }
.toast .toast-x {
  margin-left: auto; flex-shrink: 0;
  width: 24px; height: 24px; border: none; border-radius: 6px;
  background: transparent; color: var(--muted-foreground); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.toast .toast-x:hover { background: var(--accent); color: var(--foreground); }

/* ============================================================================
 * Empty state / skeletons / misc
 * ==========================================================================*/
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 44px 16px; text-align: center;
}
.empty-state .empty-ic {
  width: 56px; height: 56px; border-radius: 999px;
  background: var(--muted);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted-foreground);
}
.empty-state .empty-title { font-weight: 500; font-size: 15px; }
.empty-state .empty-desc { font-size: 14px; color: var(--muted-foreground); max-width: 384px; margin-top: 4px; }

.skeleton {
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--muted) 25%, var(--muted-50) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.4s ease infinite;
}
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.divider { height: 1px; background: var(--border); margin: 14px 0; }
.muted { color: var(--muted-foreground); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.ctr { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.num-c { font-variant-numeric: tabular-nums; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; display: inline-block; vertical-align: bottom; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.img-preview { max-height: 72px; max-width: 190px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--background); padding: 4px; }

/* list rows (dashboard widgets) */
.list-divide > li + li { border-top: 1px solid var(--border); }
.list-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 4px; border-radius: 7px; text-align: left;
  color: inherit; background: none; border: none; cursor: pointer; font: inherit;
}
.list-row.plain { cursor: default; }
a.list-row:hover, button.list-row:hover { background: var(--muted-50); }
.list-row .row-ic {
  width: 32px; height: 32px; border-radius: 999px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-badge-green); color: var(--fg-badge-green);
}
.list-row .row-ic.out { background: var(--bg-badge-red); color: var(--fg-badge-red); }
.list-row .row-main { flex: 1; min-width: 0; }
.list-row .row-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .row-sub { font-size: 12px; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .row-val { flex-shrink: 0; text-align: right; }
.list-row .row-amt { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.list-row .row-date { font-size: 12px; color: var(--muted-foreground); }
.maxh-scroll { max-height: 288px; overflow-y: auto; }

/* ============================================================================
 * Charts (SVG)
 * ==========================================================================*/
.chart-box { color: var(--muted-foreground); }
.chart-box svg { width: 100%; height: 288px; display: block; }
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  font-size: 12px; color: var(--muted-foreground);
  padding-top: 8px;
}
.chart-legend .leg { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .leg .dot { width: 8px; height: 8px; }

/* ============================================================================
 * Pagination
 * ==========================================================================*/
.pager {
  display: flex; flex-direction: column; gap: 8px;
  align-items: center; justify-content: space-between;
  font-size: 14px; color: var(--muted-foreground);
}
@media (min-width: 640px) { .pager { flex-direction: row; } }
.pager-btns { display: flex; align-items: center; gap: 4px; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--background); color: var(--foreground);
  font-size: 13px; text-decoration: none; cursor: pointer;
}
.page-btn:hover { background: var(--accent); }
.page-btn:disabled, .page-btn.disabled { opacity: .5; pointer-events: none; }
.page-cur {
  padding: 2px 12px; border-radius: var(--radius-sm);
  background: var(--muted); color: var(--foreground);
  font-size: 12px; font-weight: 500;
}
.pagination { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }

/* ============================================================================
 * Line-item editor (sales / purchases)
 * ==========================================================================*/
.line-table input, .line-table select { min-width: 70px; }
.line-table .calc { font-variant-numeric: tabular-nums; text-align: right; color: var(--muted-foreground); font-size: 13px; white-space: nowrap; }
.live-summary {
  display: flex; flex-wrap: wrap; gap: 8px 24px;
  background: var(--muted-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px; font-size: 14px;
}
.live-summary strong { font-variant-numeric: tabular-nums; }
.tax-note { font-size: 12px; color: var(--muted-foreground); margin-top: 8px; }

/* ============================================================================
 * Login page
 * ==========================================================================*/
.login-page { min-height: 100vh; display: flex; background: var(--background); color: var(--foreground); }
.login-brand-col {
  position: relative; overflow: hidden; display: none;
  background: linear-gradient(to bottom right, #059669, #047857 55%, #134e4a);
  color: #fff;
  flex-direction: column; justify-content: space-between;
  padding: 48px;
}
@media (min-width: 1024px) {
  .login-page { display: grid; grid-template-columns: 1fr 1fr; }
  .login-brand-col { display: flex; }
  .login-form-col { min-height: 100vh; }
}
@media (min-width: 1280px) { .login-brand-col { padding: 64px; } }
.login-deco { position: absolute; inset: 0; pointer-events: none; }
.login-deco .c1 { position: absolute; top: -96px; right: -96px; width: 384px; height: 384px; border-radius: 999px; background: rgba(255,255,255,.1); }
.login-deco .c2 { position: absolute; bottom: -128px; left: -128px; width: 448px; height: 448px; border-radius: 999px; background: rgba(45,212,191,.1); }
.login-deco .c3 { position: absolute; top: 33%; right: 25%; width: 160px; height: 160px; border-radius: 24px; transform: rotate(12deg); border: 1px solid rgba(255,255,255,.1); }
.login-deco .c4 { position: absolute; bottom: 25%; left: 33%; width: 96px; height: 96px; border-radius: 16px; transform: rotate(-6deg); border: 1px solid rgba(255,255,255,.1); }
.login-brand-head { position: relative; display: flex; align-items: center; gap: 12px; }
.login-brand-ic {
  border-radius: 12px; background: rgba(255,255,255,.15);
  padding: 10px; color: #fff; backdrop-filter: blur(4px);
}
.login-brand-h1 {
  position: relative; margin-top: 48px;
  max-width: 512px; font-size: 30px; font-weight: 700; line-height: 1.2; color: #fff;
}
@media (min-width: 1280px) { .login-brand-h1 { font-size: 36px; } }
.login-brand-p { position: relative; margin-top: 16px; max-width: 448px; font-size: 14px; line-height: 1.6; color: rgba(209,250,229,.85); }
.login-features {
  position: relative; margin-top: 40px;
  display: grid; gap: 16px; max-width: 512px;
}
@media (min-width: 640px) { .login-features { grid-template-columns: 1fr 1fr; } }
.login-feature {
  display: flex; gap: 12px; align-items: flex-start;
  background: rgba(255,255,255,.1); border-radius: 12px; padding: 12px;
  backdrop-filter: blur(2px);
}
.login-feature .ic { color: #a7f3d0; margin-top: 2px; }
.login-feature .ft { font-size: 14px; font-weight: 600; color: #fff; }
.login-feature .fx { margin-top: 2px; font-size: 12px; line-height: 1.45; color: rgba(209,250,229,.8); }
.login-brand-foot { position: relative; margin-top: 40px; display: flex; align-items: center; gap: 16px; font-size: 12px; color: rgba(209,250,229,.8); }
.login-form-col {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 16px; min-height: 100vh;
}
@media (min-width: 640px) { .login-form-col { padding: 40px 32px; } }
.login-mobile-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
@media (min-width: 1024px) { .login-mobile-brand { display: none; } }
.login-mobile-ic {
  border-radius: 12px; padding: 10px; color: #fff;
  background: linear-gradient(to bottom right, var(--emerald), var(--teal-600));
  box-shadow: var(--shadow-md);
}
.login-form-wrap { width: 100%; max-width: 448px; display: flex; flex-direction: column; gap: 24px; }
.login-welcome { display: none; }
@media (min-width: 1024px) { .login-welcome { display: block; } }
.login-welcome h2 { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.login-welcome p { margin-top: 4px; font-size: 14px; color: var(--muted-foreground); }
.login-card-title { font-size: 18px; font-weight: 600; }
.login-input-wrap { position: relative; }
.login-input-wrap .ic {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted-foreground); pointer-events: none;
}
.login-input-wrap .input { padding-left: 34px; }
.login-input-wrap.pw .input { padding-right: 38px; }
.pw-toggle {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border: none; border-radius: 6px;
  background: transparent; color: var(--muted-foreground); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.pw-toggle:hover { color: var(--foreground); }
.demo-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--background); padding: 8px 12px; text-align: left; cursor: pointer;
  color: inherit; font: inherit;
  transition: border-color .12s ease, background .12s ease;
}
.demo-row:hover { border-color: #6ee7b7; background: var(--bg-badge-green); }
.login-disclaimer { margin-top: 32px; max-width: 448px; text-align: center; font-size: 11px; line-height: 1.6; color: var(--muted-foreground); }

/* ============================================================================
 * Invoice / bill document (print)
 * ==========================================================================*/
.print-body { background: #eceeea; }
.doc-sheet {
  max-width: 860px; margin: 16px auto; background: #fff; color: #111;
  padding: 32px; border-radius: 6px; box-shadow: 0 2px 18px rgba(0,0,0,.12);
  font-size: 14px;
}
.doc-head {
  display: flex; justify-content: space-between; gap: 16px;
  border-bottom: 3px solid #047857; padding-bottom: 14px;
}
.doc-head .co img.logo { max-height: 74px; max-width: 190px; object-fit: contain; }
.doc-head .co .co-name { font-size: 19px; font-weight: 700; }
.doc-head .co .co-addr { font-size: 12px; color: #444; line-height: 1.5; margin-top: 2px; }
.doc-kind { text-align: right; }
.doc-kind h2 { margin: 0 0 4px; font-size: 21px; color: #047857; letter-spacing: .02em; }
.doc-meta { margin-top: 6px; font-size: 12.5px; line-height: 1.55; }
.doc-meta strong { font-weight: 600; }
.doc-parties { display: flex; gap: 16px; margin: 16px 0; }
.doc-parties .party { flex: 1; border: 1px solid #dfe3df; border-radius: 8px; padding: 10px 12px; }
.doc-parties .party h4 { margin: 0 0 4px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: #66736c; font-weight: 600; }
.doc-parties .party .p-name { font-weight: 600; }
.doc-parties .party .p-addr { font-size: 12px; color: #444; line-height: 1.5; }
table.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table th, .doc-table td { border: 1px solid #dfe3df; padding: 6px 8px; text-align: left; }
.doc-table th { background: #f0f3f0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.doc-table td.num, .doc-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-totals { margin-left: auto; width: 320px; margin-top: 12px; }
.doc-totals .row { display: flex; justify-content: space-between; padding: 4px 8px; font-size: 13px; }
.doc-totals .row.grand { background: #047857; color: #fff; font-weight: 700; border-radius: 6px; font-size: 15px; }
.doc-words { margin: 12px 0; font-style: italic; font-size: 13px; color: #40514a; }
.doc-footer-blocks { display: flex; gap: 16px; margin-top: 16px; align-items: flex-start; }
.doc-footer-blocks .block { flex: 1; border: 1px solid #dfe3df; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.doc-sign { text-align: center; margin-top: 22px; }
.doc-sign img { max-height: 60px; max-width: 190px; object-fit: contain; }
.doc-seal { max-height: 92px; max-width: 92px; object-fit: contain; margin-top: -46px; margin-left: 150px; opacity: .85; }
.print-bar { display: flex; gap: 8px; justify-content: flex-end; max-width: 860px; margin: 16px auto 0; }

/* barcode */
.doc-barcode { margin-top: 6px; }

/* ============================================================================
 * Print
 * ==========================================================================*/
@media print {
  body { background: #fff; }
  .no-print, .print-bar, .sidebar, .topbar, .nav-backdrop, .menu-toggle,
  .app-footer, .toast-wrap, .sidebar-foot, .brand-toggle { display: none !important; }
  .main-col, html.sb-collapsed .main-col { padding-left: 0 !important; }
  .content { padding: 0 !important; }
  .card { box-shadow: none !important; border-color: #dfe3df; }
  .doc-sheet { box-shadow: none; margin: 0; padding: 0; border-radius: 0; max-width: none; }
  @page { size: A4; margin: 10mm; }
}

/* ============================================================================
 * Responsive tweaks
 * ==========================================================================*/
@media (max-width: 640px) {
  .page-title { font-size: 20px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .doc-sheet { padding: 16px; }
  .doc-parties, .doc-footer-blocks { flex-direction: column; }
  .search-box { max-width: none; }
  .hide-sm { display: none !important; }
}
