:root {
	--brand: #4f46e5;
	--brand-dark: #4338ca;
	--bg: #f7f7fb;
	--panel: #ffffff;
	--border: #ececf1;
	--text: #111827;
	--text-muted: #6b7280;
	--text-faint: #9ca3af;
	--sidebar-bg: #ffffff;
	--green-bg: #dcfce7; --green-fg: #16a34a;
	--amber-bg: #fef3c7; --amber-fg: #d97706;
	--purple-bg: #e0e7ff; --purple-fg: #4f46e5;
	--red-bg: #fee2e2; --red-fg: #dc2626;
	--gray-bg: #f3f4f6; --gray-fg: #6b7280;
	--shadow: 0 1px 2px rgba(16,24,40,0.04);
	--radius: 12px;
}
html.dark {
	--bg: #0f1117;
	--panel: #171922;
	--border: #262835;
	--text: #f3f4f6;
	--text-muted: #9ca3af;
	--text-faint: #6b7280;
	--sidebar-bg: #12141c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
	font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
	font-size: 14px;
}
a { color: inherit; text-decoration: none; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
	width: 264px;
	flex-shrink: 0;
	background: var(--sidebar-bg);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	position: sticky;
	top: 0;
	height: 100vh;
}
.sidebar-brand {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 20px 20px 16px;
}
.sidebar-brand .logo-icon {
	width: 38px; height: 38px;
	border-radius: 10px;
	background: linear-gradient(135deg, #6366f1, #4338ca);
	display: flex; align-items: center; justify-content: center;
	color: #fff; font-size: 18px; flex-shrink: 0;
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 16px; line-height: 1.2; }
.sidebar-brand .brand-tag { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 12px; }
.nav-section-label {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.06em;
	color: var(--text-faint);
	text-transform: uppercase;
	margin: 18px 10px 6px;
}
.nav-item {
	display: flex; align-items: center; gap: 10px;
	padding: 9px 12px;
	border-radius: 8px;
	color: var(--text);
	font-size: 13.5px;
	font-weight: 500;
	margin-bottom: 2px;
}
.nav-item .nav-icon { width: 18px; text-align: center; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--gray-bg); }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item.active .nav-icon { opacity: 1; }

.sidebar-user {
	border-top: 1px solid var(--border);
	padding: 14px 20px;
	display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0; }
.sidebar-user .u-name { font-weight: 600; font-size: 13px; }
.sidebar-user .u-email { font-size: 11px; color: var(--text-muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user { position: relative; }
.sidebar-user-menu { position: absolute; bottom: 60px; left: 14px; right: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); display: none; overflow: hidden; z-index: 40; }
.sidebar-user-menu.open { display: block; }
.sidebar-user-menu a { display: block; padding: 10px 14px; font-size: 13px; }
.sidebar-user-menu a:hover { background: var(--gray-bg); }

/* Main area */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
	height: 66px; flex-shrink: 0;
	display: flex; align-items: center; justify-content: space-between;
	padding: 0 28px;
	border-bottom: 1px solid var(--border);
	background: var(--panel);
	position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-search {
	display: flex; align-items: center; gap: 8px;
	background: var(--gray-bg); border-radius: 9px; padding: 8px 14px;
	width: 260px; color: var(--text-muted); font-size: 13px;
}
.topbar-search input { border: none; background: transparent; outline: none; width: 100%; color: var(--text); font-size: 13px; }
.icon-btn {
	width: 36px; height: 36px; border-radius: 9px;
	display: flex; align-items: center; justify-content: center;
	background: transparent; border: none; cursor: pointer; color: var(--text-muted);
	position: relative; font-size: 16px;
}
.icon-btn:hover { background: var(--gray-bg); }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; border: 2px solid var(--panel); }
.topbar-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; cursor: pointer; }

.content { padding: 26px 28px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 26px; margin: 0 0 4px; font-weight: 700; }
.page-head p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.btn {
	display: inline-flex; align-items: center; gap: 6px;
	background: var(--brand); color: #fff; border: none;
	padding: 10px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
	cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--gray-bg); }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* Cards */
.cards-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .cards-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-icon { width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.stat-value { font-size: 27px; font-weight: 700; margin-top: 10px; }
.stat-foot { color: var(--text-faint); font-size: 12px; margin-top: 3px; }

.panels-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 1000px) { .panels-row { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 2px; font-size: 15px; }
.panel .panel-sub { color: var(--text-faint); font-size: 12px; margin: 0 0 12px; }
.empty-note { color: var(--text-faint); padding: 18px 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.list-row:last-child { border-bottom: none; }

/* Search + toolbar for CRUD pages */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 9px; padding: 9px 14px; width: 320px; color: var(--text-muted); }
.search-box input { border: none; outline: none; background: transparent; width: 100%; color: var(--text); font-size: 13.5px; }
.record-count { color: var(--text-faint); font-size: 12.5px; }

/* Data table */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th { text-align: left; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--bg); }
table.data-table td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--bg); }
.row-actions a, .row-actions button { color: var(--text-muted); background: none; border: none; cursor: pointer; padding: 4px; font-size: 14px; }
.row-actions a:hover, .row-actions button:hover { color: var(--text); }
.row-actions .danger:hover { color: #dc2626; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--green-bg); color: var(--green-fg); }
.badge-amber { background: var(--amber-bg); color: var(--amber-fg); }
.badge-red { background: var(--red-bg); color: var(--red-fg); }
.badge-gray { background: var(--gray-bg); color: var(--gray-fg); }
.badge-purple { background: var(--purple-bg); color: var(--purple-fg); }

.balance-pos { color: #dc2626; font-weight: 700; }
.balance-neg { color: #16a34a; font-weight: 700; }
.balance-zero { color: var(--text-faint); }
.stock-low { color: #dc2626; font-weight: 700; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,17,23,0.55); z-index: 100; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 40px 16px; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--panel); border-radius: 14px; width: 100%; max-width: 620px; padding: 28px 30px 26px; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-box.modal-wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
	width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
	font-size: 13.5px; background: var(--panel); color: var(--text); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); }
.field textarea { resize: vertical; min-height: 70px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* Line items repeater (Purchases / Sales modals) */
.line-items-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.line-items-table th { text-align: left; font-size: 11px; color: var(--text-faint); padding: 4px 6px; text-transform: uppercase; }
.line-items-table td { padding: 4px 6px; vertical-align: middle; }
.line-items-table select, .line-items-table input { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); color: var(--text); font-size: 13px; }
.line-total-cell { font-weight: 600; white-space: nowrap; font-size: 13px; }
.remove-line { color: #dc2626; background: none; border: none; cursor: pointer; font-size: 16px; }
.summary-box { background: var(--bg); border-radius: 10px; padding: 14px 16px; margin-top: 14px; }
.summary-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.summary-row.total-row { font-weight: 700; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.summary-row .balance-amt { color: #dc2626; font-weight: 700; }

.notice { padding: 12px 16px; border-radius: 9px; margin-bottom: 16px; font-size: 13.5px; }
.notice-success { background: var(--green-bg); color: var(--green-fg); }
.notice-error { background: var(--red-bg); color: var(--red-fg); }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 40px 36px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.login-box .logo-icon { margin: 0 auto 14px; }
.login-box h1 { text-align: center; font-size: 20px; margin: 0 0 4px; }
.login-box p.sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 24px; }
.login-box .field { margin-bottom: 14px; }
.login-box .btn { width: 100%; justify-content: center; margin-top: 6px; }
.hint-box { background: var(--gray-bg); border-radius: 8px; padding: 10px 12px; font-size: 12px; color: var(--text-muted); margin-top: 18px; }

@media (max-width: 860px) {
	.sidebar { position: fixed; left: -280px; z-index: 60; transition: left 0.2s; box-shadow: 0 0 0 rgba(0,0,0,0); }
	.sidebar.open { left: 0; box-shadow: 10px 0 30px rgba(0,0,0,0.2); }
	.topbar-search { display: none; }
	.form-grid { grid-template-columns: 1fr; }
}

/* Elements that only make sense inside the Android app (e.g. barcode scan
   buttons) - hidden by default, shown once mobile-bridge.js detects it's
   running inside Capacitor and adds .sl-mobile-app to <html>. */
.sl-mobile-app-only { display: none !important; }
html.sl-mobile-app .sl-mobile-app-only { display: inline-flex !important; align-items: center; gap: 4px; }
.scan-btn { background: var(--gray-bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.scan-btn:hover { background: var(--border); }
