/* =========================================================
   PipAlgo POS — Stylesheet
   Light theme | Blue accent #1a56db | Inter / JetBrains Mono
   ========================================================= */

:root {
    --brand: #1a56db;
    --brand-dark: #1443b0;
    --brand-light: #eaf0fd;
    --green: #0f9d58;
    --green-light: #e6f7ee;
    --red: #d93025;
    --red-light: #fdeceb;
    --amber: #b8860b;
    --amber-light: #fbf3e0;

    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e4e8f0;
    --text: #1a1d29;
    --text-muted: #6b7280;
    --text-faint: #9aa1b1;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);

    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}

.mono, .money, .num {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    font-variant-numeric: tabular-nums;
}

a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 4px 0; letter-spacing: -0.01em; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo-mark {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px;
    flex-shrink: 0;
}
.sidebar-brand .brand-text { line-height: 1.15; }
.sidebar-brand .brand-text strong { display: block; font-size: 15px; }
.sidebar-brand .brand-text span { font-size: 11.5px; color: var(--text-muted); }

.sidebar-nav { padding: 14px 12px; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-faint); padding: 14px 10px 6px;
    font-weight: 600;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; margin: 2px 0;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px; font-weight: 500;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .75; }
.sidebar-nav a:hover { background: var(--bg); }
.sidebar-nav a.active { background: var(--brand-light); color: var(--brand-dark); }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
    padding: 14px 16px; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand-light); color: var(--brand-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar-footer .who { line-height: 1.2; overflow: hidden; }
.sidebar-footer .who strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who span { font-size: 11.5px; color: var(--text-muted); text-transform: capitalize; }
.sidebar-footer .logout-btn { margin-left: auto; color: var(--text-muted); }

.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.topbar .hamburger {
    width: 38px; height: 38px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    display: flex; align-items: center; justify-content: center;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(15,18,30,.4); z-index: 39;
}

.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.page-header p { color: var(--text-muted); margin: 4px 0 0; font-size: 13.5px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 600; cursor: pointer;
    border: 1px solid transparent; transition: all .15s ease;
    white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 34px; height: 34px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 18px 20px; }
.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-card .stat-delta { font-size: 12px; margin-top: 4px; font-weight: 600; }
.stat-card.profit .stat-value { color: var(--green); }
.stat-card.loss .stat-value { color: var(--red); }
.delta-up { color: var(--green); }
.delta-down { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13.5px; }
table th {
    text-align: left; padding: 11px 14px; background: #fafbfd;
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 600;
    white-space: nowrap;
}
table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #fafbfd; }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
}
.badge-green { background: var(--green-light); color: var(--green); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-amber { background: var(--amber-light); color: var(--amber); }
.badge-gray { background: #eef0f4; color: var(--text-muted); }
.badge-blue { background: var(--brand-light); color: var(--brand-dark); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input, select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.input-group { position: relative; }
.input-group .prefix {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 14px; pointer-events: none;
}
.input-group input { padding-left: 26px; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; }
.alert-success { background: var(--green-light); color: #0b7a44; }
.alert-error { background: var(--red-light); color: #b0201a; }
.alert-info { background: var(--brand-light); color: var(--brand-dark); }

/* ---------- Login page ---------- */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #f5f7fb 0%, #eaf0fd 100%); padding: 20px;
}
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-md); padding: 32px 28px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 22px; text-align: center; }
.auth-logo .logo-mark { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 12px; font-size: 20px; }

/* ---------- POS screen ---------- */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 18px; align-items: start; }
.pos-search { margin-bottom: 14px; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.product-tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px; cursor: pointer; transition: all .12s ease; text-align: left;
}
.product-tile:hover { border-color: var(--brand); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.product-tile:disabled, .product-tile.out-of-stock { opacity: .45; cursor: not-allowed; }
.product-tile .p-thumb {
    width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); background: var(--brand-light);
    display: flex; align-items: center; justify-content: center; color: var(--brand); font-weight: 700; font-size: 20px;
    margin-bottom: 8px; overflow: hidden;
}
.product-tile .p-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-tile .p-name { font-size: 12.5px; font-weight: 600; line-height: 1.3; margin-bottom: 4px; min-height: 32px; }
.product-tile .p-price { font-size: 13.5px; font-weight: 700; color: var(--brand); }
.product-tile .p-stock { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.cart-panel { position: sticky; top: 18px; }
.cart-items { max-height: 340px; overflow-y: auto; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cart-line:last-child { border-bottom: none; }
.cart-line .cl-name { flex: 1; font-size: 13px; font-weight: 600; }
.cart-line .cl-sub { font-size: 11.5px; color: var(--text-muted); }
.qty-control { display: flex; align-items: center; gap: 6px; }
.qty-control button {
    width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface);
    display: flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 700;
}
.qty-control span { min-width: 20px; text-align: center; font-size: 13px; font-weight: 600; }
.cart-totals { padding-top: 12px; border-top: 1px dashed var(--border); margin-top: 8px; }
.cart-totals .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; }
.cart-totals .row.grand { font-size: 17px; font-weight: 700; padding-top: 8px; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-green { color: var(--green); } .text-red { color: var(--red); }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state svg { opacity: .3; margin-bottom: 10px; }
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15,18,30,.45);
    z-index: 100; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal-box .card-header { position: sticky; top: 0; background: var(--surface); }
.close-x { cursor: pointer; color: var(--text-muted); background: none; border: none; font-size: 20px; line-height: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .pos-layout { grid-template-columns: 1fr; }
    .cart-panel { position: static; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar { display: flex; }
    .sidebar-backdrop.open { display: block; }
    .content { padding: 16px; }
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 12px 14px; }
    .stat-card .stat-value { font-size: 19px; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    table th, table td { padding: 9px 10px; font-size: 12.5px; }
}
