/* N-Soft Distro — shared design system
   Primary blue (#00739F) and dark navy sampled directly from the app's own
   logo/icon (NsoftDistro.ico) so the web app matches the brand instead of
   an arbitrary default. Accent hues (teal/purple/amber/rose) exist purely
   for visual variety — stat cards, category chips — never for meaning
   (success/danger/warning carry meaning; accents don't). */

:root {
  --color-bg: #f4f6f8;
  --color-bg-subtle: #eaeef2;
  --color-surface: #ffffff;
  --color-surface-2: #f6f9fb;
  --color-border: #e0e6ec;
  --color-border-strong: #c8d2db;
  --color-text: #142430;
  --color-text-muted: #5b7285;
  --color-text-faint: #94a7b5;

  --color-primary: #00739f;
  --color-primary-hover: #005d82;
  --color-primary-soft: #e2f2f9;

  --color-danger: #dc2626;
  --color-danger-soft: #fef2f2;
  --color-success: #16a34a;
  --color-success-soft: #f0fdf4;
  --color-warning: #d97706;
  --color-warning-soft: #fffbeb;

  --color-accent-teal: #0d9488;
  --color-accent-teal-soft: #ecfdf9;
  --color-accent-purple: #7c3aed;
  --color-accent-purple-soft: #f3ecfe;
  --color-accent-rose: #e11d48;
  --color-accent-rose-soft: #fef1f4;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(14, 35, 48, 0.07);
  --shadow: 0 2px 10px rgba(14, 35, 48, 0.09);
  --shadow-lg: 0 12px 32px rgba(14, 35, 48, 0.16);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-width: 236px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #0d1417;
    --color-bg-subtle: #131b1f;
    --color-surface: #172025;
    --color-surface-2: #1c262c;
    --color-border: #263038;
    --color-border-strong: #34414b;
    --color-text: #e8eef1;
    --color-text-muted: #93a7b3;
    --color-text-faint: #5f7481;

    --color-primary: #4fb8e0;
    --color-primary-hover: #7dcbeb;
    --color-primary-soft: #113347;

    --color-danger: #f87171;
    --color-danger-soft: #3a1d1f;
    --color-success: #4ade80;
    --color-success-soft: #16281c;
    --color-warning: #fbbf24;
    --color-warning-soft: #332510;

    --color-accent-teal: #2dd4bf;
    --color-accent-teal-soft: #0f2e2a;
    --color-accent-purple: #a78bfa;
    --color-accent-purple-soft: #271f3d;
    --color-accent-rose: #fb7185;
    --color-accent-rose-soft: #3a1521;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --color-bg: #0d1417;
  --color-bg-subtle: #131b1f;
  --color-surface: #172025;
  --color-surface-2: #1c262c;
  --color-border: #263038;
  --color-border-strong: #34414b;
  --color-text: #e8eef1;
  --color-text-muted: #93a7b3;
  --color-text-faint: #5f7481;

  --color-primary: #4fb8e0;
  --color-primary-hover: #7dcbeb;
  --color-primary-soft: #113347;

  --color-danger: #f87171;
  --color-danger-soft: #3a1d1f;
  --color-success: #4ade80;
  --color-success-soft: #16281c;
  --color-warning: #fbbf24;
  --color-warning-soft: #332510;

  --color-accent-teal: #2dd4bf;
  --color-accent-teal-soft: #0f2e2a;
  --color-accent-purple: #a78bfa;
  --color-accent-purple-soft: #271f3d;
  --color-accent-rose: #fb7185;
  --color-accent-rose-soft: #3a1521;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.5rem; }

a { color: var(--color-primary); }

/* ---------- Card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}

/* ---------- Forms ---------- */
input, select, button, textarea {
  font: inherit;
  color: inherit;
}

input, select, textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:hover, select:hover, textarea:hover { border-color: var(--color-text-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

label { font-weight: 500; }

.field { margin-bottom: 0.75rem; }
.field label { display: block; font-size: 0.82rem; margin-bottom: 0.3rem; color: var(--color-text-muted); }
.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }

/* ---------- Buttons ---------- */
button {
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
button:hover { background: var(--color-bg-subtle); border-color: var(--color-text-faint); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { background: var(--color-surface); border-color: var(--color-border-strong); }

button.primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
button.primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

button.danger { color: var(--color-danger); border-color: var(--color-danger); background: transparent; }
button.danger:hover { background: var(--color-danger-soft); }

.error-text { color: var(--color-danger); font-size: 0.85rem; }

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

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
}

.app-sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  padding: 0.5rem 0.6rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.app-sidebar .brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
}

.app-sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; }

.app-sidebar a.nav-link {
  display: block;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}
.app-sidebar a.nav-link:hover { background: var(--color-bg-subtle); color: var(--color-text); }
.app-sidebar a.nav-link.active { background: var(--color-primary-soft); color: var(--color-primary); }

/* Collapsible nav groups (Masters, Sales, Purchases, Other, Admin) — only
   the group containing the current page auto-expands, so the sidebar stays
   short instead of one long flat list. */
.nav-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.6rem;
  border: none;
  background: none;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.nav-group-toggle:hover { background: var(--color-bg-subtle); color: var(--color-text); }
.nav-group-chevron { font-size: 0.7rem; transition: transform 0.15s ease; color: var(--color-text-faint); }
.nav-group.expanded .nav-group-chevron { transform: rotate(90deg); }
.nav-group-items {
  display: none;
  padding-left: 0.75rem;
  border-left: 1px solid var(--color-border);
  margin: 0.1rem 0 0.3rem 0.9rem;
}
.nav-group.expanded .nav-group-items { display: block; }
.nav-group-items a.nav-link { font-weight: 500; font-size: 0.85rem; }

.app-sidebar .sidebar-footer {
  border-top: 1px solid var(--color-border);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.app-sidebar .sidebar-footer a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.app-sidebar .sidebar-footer a:hover { background: var(--color-bg-subtle); color: var(--color-text); }

/* Right column: a persistent top bar (never overwritten by page scripts,
   unlike #app-main which every page replaces wholesale) showing which
   business this instance belongs to, then the page content below it. */
.app-content-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
  padding: 0.6rem 2rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  flex-shrink: 0;
  text-align: right;
}
.app-main { flex: 1; padding: 2rem; max-width: 100%; overflow-x: auto; }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.theme-toggle button {
  border: none;
  border-radius: 0;
  background: var(--color-surface);
  padding: 0.35rem 0.55rem;
  font-size: 0.85rem;
  line-height: 1;
}
.theme-toggle button:not(:last-child) { border-right: 1px solid var(--color-border-strong); }
.theme-toggle button.active { background: var(--color-primary-soft); color: var(--color-primary); }
.theme-toggle button:hover { background: var(--color-bg-subtle); }
.theme-toggle button.active:hover { background: var(--color-primary-soft); }

/* Floating toggle used on pages without the sidebar (login, change-password) */
.theme-toggle-floating { position: fixed; top: 1rem; right: 1rem; z-index: 10; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 1rem;
}
table { width: 100%; border-collapse: collapse; }
.table-wrap table { margin-top: 0; }
th, td { text-align: left; padding: 0.65rem 1rem; border-bottom: 1px solid var(--color-border); font-size: 0.88rem; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; background: var(--color-surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--color-bg-subtle); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--color-border-strong); background: var(--color-surface-2); }

.row-actions button { margin-right: 0.4rem; padding: 0.3rem 0.6rem; font-size: 0.82rem; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { max-width: 240px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tabs button { padding: 0.5rem 1rem; font-size: 0.85rem; }
.tabs button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ---------- Dialog ---------- */
dialog {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 400px;
  max-width: calc(100vw - 2rem);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(10, 12, 16, 0.5); backdrop-filter: blur(1px); }

/* ---------- Status badges (class="badge badge-*") ---------- */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-info { background: var(--color-primary-soft); color: var(--color-primary); }
.badge-purple { background: var(--color-accent-purple-soft); color: var(--color-accent-purple); }
.badge-muted { background: var(--color-bg-subtle); color: var(--color-text-muted); }

/* ---------- Stat cards (dashboard) — accent variants for visual variety,
   purely decorative, not status-meaningful like the badges above ---------- */
.stat-card { border-top: 3px solid var(--color-primary); }
.stat-card.accent-teal { border-top-color: var(--color-accent-teal); }
.stat-card.accent-purple { border-top-color: var(--color-accent-purple); }
.stat-card.accent-amber { border-top-color: var(--color-warning); }
.stat-card.accent-rose { border-top-color: var(--color-accent-rose); }

/* ---------- Totals block (sales/purchases/quotation entry forms) ---------- */
.totals { text-align: right; margin-top: 0.75rem; font-size: 0.95rem; }
.totals div { margin-bottom: 0.25rem; }
.totals .grand { font-weight: 700; font-size: 1.1rem; }
