/* Agarwalla Plastic Hub — ERP shared stylesheet */

:root {
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-glow: rgba(37, 99, 235, 0.25);
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --bg: #f1f4f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e6ea;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 8px 24px rgba(20, 20, 40, 0.06);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0 0 12px; }
table { border-collapse: collapse; width: 100%; }

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

.sidebar {
  width: var(--sidebar-w);
  background: #111827;
  color: #e5e7eb;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: block;
  padding: 20px 20px 16px;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .brand span { color: #60a5fa; }
.sidebar nav { padding: 10px 0 24px; }
.sidebar .nav-group-title {
  padding: 14px 20px 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #9ca3af;
}
.sidebar a.nav-link {
  display: block;
  padding: 9px 20px;
  color: #d1d5db;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,0.05); color: #fff; }
.sidebar a.nav-link.active {
  background: rgba(37, 99, 235, 0.18);
  color: #fff;
  border-left-color: var(--accent);
  font-weight: 600;
}

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

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .fy-badge {
  background: #eef2ff;
  color: var(--accent-dark);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.82rem;
}
.topbar .user-menu { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; color: var(--muted); }

.content { padding: 24px; flex: 1; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h1 { font-size: 1.35rem; margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.88rem;
  border: none;
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease, opacity .1s ease;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 6px 16px var(--accent-glow); }
.btn-primary:hover { opacity: .93; }
.btn-primary:active { transform: translateY(1px); }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-outline { background: #fff; color: var(--red); border: 1px solid #fca5a5; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- Cards ---------------- */
.card { background: var(--card-bg); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 22px; }
.card + .card { margin-top: 18px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 18px 20px; }
.stat-card .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 1.6rem; font-weight: 800; margin-top: 4px; }
.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }
.stat-card .value.amber { color: var(--amber); }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 5px; }
.field .hint { color: var(--muted); font-size: 0.78rem; margin-top: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=password], input[type=tel], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: stretch; }
.form-row > .card { margin-top: 0; }
.radio-group { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-group label { font-weight: 500; display: flex; align-items: center; gap: 6px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 700; font-size: 0.85rem; }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); }
table.data { width: 100%; }
table.data th, table.data td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { background: #f9fafb; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.data tbody tr:hover { background: #f9fafb; }
table.data tfoot td { font-weight: 700; background: #f9fafb; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }

.line-items-table input, .line-items-table select { min-width: 90px; }
.line-items-table td { white-space: normal; }

/* ---------------- Badges / status ---------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f3f4f6; color: #4b5563; }
.badge-blue { background: #dbeafe; color: #1e40af; }

/* ---------------- Alerts / flash ---------------- */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 14px; font-size: 0.9rem; }
.alert-success { background: #dcfce7; color: #166534; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 20, 30, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-box {
  background: var(--card-bg); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 26px; max-width: 420px; width: 100%;
}
.modal-box h3 { margin-top: 0; }
.modal-box .modal-actions { margin-top: 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* ---------------- Filters bar ---------------- */
.filters { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 16px; display: flex; gap: 12px; flex-wrap: end; align-items: flex-end; flex-wrap: wrap; }
.filters .field { margin-bottom: 0; min-width: 160px; }

/* ---------------- Login ---------------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }

/* ---------------- Misc ---------------- */
.text-muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---------------- Print (for report pages printed directly from the app shell) ---------------- */
@media print {
  .sidebar, .topbar, .page-actions, .filters, .no-print { display: none !important; }
  .app-shell, .main-col, .content { display: block !important; padding: 0 !important; margin: 0 !important; }
  body { background: #fff; }
}

/* ---- Line-item product type-ahead + stock availability ---- */
.li-product-cell { position: relative; }
.li-product-search { width: 100%; box-sizing: border-box; }
.li-avail.stock-short { color: #dc2626; font-weight: 700; }

/* Body-level results overlay (never clipped by the table scroll container) */
.li-search-dropdown {
  position: fixed; z-index: 1000;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 8px;
  max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}
.li-sr-item { padding: 11px 12px; cursor: pointer; border-bottom: 2px solid #cbd5e1; }
.li-sr-item:last-child { border-bottom: none; }
.li-sr-item.active, .li-sr-item:hover { background: #eff6ff; }
.li-sr-top { font-size: 13.5px; color: #0f172a; line-height: 1.3; }
.li-sr-code { font-weight: 700; color: #1d4ed8; margin-right: 4px; }
.li-sr-sub { display: flex; flex-wrap: wrap; gap: 5px 6px; margin-top: 5px; }
.li-tag {
  display: inline-flex; align-items: baseline; gap: 4px;
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 1px 7px; font-size: 11.5px; line-height: 1.6; white-space: nowrap;
}
.li-tag-k { color: #94a3b8; font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.li-tag-v { color: #0f172a; font-weight: 600; }
.li-tag-price { background: #f0fdf4; border-color: #bbf7d0; }
.li-tag-price .li-tag-v { color: #15803d; }
.li-tag-stock { background: #eff6ff; border-color: #bfdbfe; }
.li-tag-stock .li-tag-v { color: #1d4ed8; }
.li-no-result { padding: 10px 12px; color: #94a3b8; font-size: 13px; }
@media (max-width: 640px) {
  .li-sr-item { padding: 12px 14px; }   /* larger touch targets on mobile */
  .li-sr-top { font-size: 15px; }
  .li-sr-sub { gap: 6px; margin-top: 7px; }
  .li-tag { font-size: 12.5px; padding: 3px 9px; }
  .li-tag-k { font-size: 10.5px; }
}

/* ---- Party outstanding panel (purchase/sale/payment screens) ---- */
.outstanding-box {
  margin-top: 12px; padding: 12px 14px;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
}
.outstanding-box .ob-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #475569; margin-bottom: 8px; }
.outstanding-box .ob-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.outstanding-box .ob-cell {
  display: flex; flex-direction: column; min-width: 110px; flex: 1 1 110px;
  padding: 8px 10px; background: #fff; border: 1px solid #e2e8f0; border-radius: 6px;
}
.outstanding-box .ob-l { font-size: 11px; color: #64748b; }
.outstanding-box .ob-v { font-size: 15px; font-weight: 600; color: #0f172a; }
.outstanding-box .ob-balance { background: #fff7ed; border-color: #fed7aa; }
.outstanding-box .ob-balance .ob-v { color: #b45309; }

/* ---- Report helpers ---- */
.section-title { font-size: 0.95rem; font-weight: 700; color: #334155; margin: 20px 0 8px; }
.report-table th, .report-table td { white-space: nowrap; }
.report-table td.nowrap, .report-table th.nowrap { white-space: nowrap; }
.report-head { display: none; }
.only-print { display: none; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* Product Management — per-unit stock edit grid */
.stock-edit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stock-edit-grid .field { margin: 0; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px; background: #f8fafc; }
.stock-edit-grid .field.has-stock { background: #ecfdf5; border-color: #a7f3d0; }
.stock-edit-grid .field input { width: 100%; box-sizing: border-box; }

/* Document summary strip (returns: original bill/invoice header) */
.doc-summary { display: flex; flex-wrap: wrap; gap: 10px; }
.doc-summary > div {
  display: flex; flex-direction: column; min-width: 120px; flex: 1 1 120px;
  padding: 8px 12px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px;
}
.doc-summary .k { font-size: 11px; color: #64748b; }
.doc-summary .v { font-size: 15px; font-weight: 600; color: #0f172a; }

/* Stock report — two search modes */
.stock-search-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.search-mode { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px 14px; }
.search-mode-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #475569; margin-bottom: 8px; }
.search-mode input[type=text] { width: 100%; box-sizing: border-box; }
.search-mode-row { display: flex; gap: 8px; flex-wrap: wrap; }
.search-mode-row select { flex: 1 1 120px; min-width: 0; }
.search-mode-row input[type=text] { flex: 2 1 180px; min-width: 0; }
.stock-toggles { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.selected-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 14px;
}
.selected-banner .clear-x { color: #1d4ed8; font-weight: 600; text-decoration: none; white-space: nowrap; }
@media (max-width: 760px) {
  .stock-search-grid { grid-template-columns: 1fr; }
}

/* Stock report row highlighting */
.stock-table tr.row-low  td { background: #fff7ed; }   /* limited stock (< threshold) */
.stock-table tr.row-low:hover td { background: #ffedd5; }
.stock-table tr.row-neg  td { background: #fef2f2; }   /* negative stock */
.stock-table tr.row-neg:hover td { background: #fee2e2; }
.stock-table tr.row-out  td { color: #94a3b8; }        /* zero stock (muted) */
@media print {
  .only-print, .report-head { display: block !important; margin-bottom: 10px; font-size: 12px; }
}

/* ---- Mobile navigation drawer (all pages) ---- */
.nav-toggle {
  display: none; background: none; border: none; cursor: pointer;
  width: 40px; height: 40px; padding: 8px; margin-right: 4px; border-radius: 8px; color: #334155;
}
.nav-toggle:hover { background: #f1f5f9; }
.nav-toggle svg { width: 22px; height: 22px; }
.nav-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 45;
}
.topbar-left { display: flex; align-items: center; gap: 6px; }

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,0.25);
  }
  body.nav-open .sidebar { transform: translateX(0) !important; }
  body.nav-open .nav-overlay { display: block; }
  .topbar { padding: 0 14px; }
  .content { padding: 16px 14px; }
  .page-header { flex-wrap: wrap; gap: 8px; }
  .topbar .user-menu { gap: 8px; }
  .topbar .user-menu span { display: none; }   /* hide long name, keep buttons */
}
@media (max-width: 480px) {
  .topbar .fy-badge { font-size: 0.72rem; padding: 4px 8px; }
  .btn.btn-sm { padding: 5px 8px; }
}

