* { box-sizing: border-box; }

:root {
    --bg: #f3f5fb;
    --surface: #ffffff;
    --surface-alt: #f8f9fc;
    --border: #e6e8f0;
    --text: #1c2033;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;

    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;

    --success-bg: #ecfdf5;
    --success-text: #047857;
    --success-border: #a7f3d0;

    --error-bg: #fef2f2;
    --error-text: #b91c1c;
    --error-border: #fecaca;

    --danger: #dc2626;
    --danger-dark: #b91c1c;

    --sidebar-bg: #171a2b;
    --sidebar-bg-active: #262a44;
    --sidebar-text: #b6b9d0;
    --sidebar-text-active: #ffffff;

    --radius-sm: 6px;
    --radius: 12px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

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

/* ---------- App shell ---------- */

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    padding: 0.5rem 0.6rem 1.5rem;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo svg {
    width: 18px;
    height: 18px;
    color: #fff;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
}

.sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
}

.sidebar-nav a.active svg {
    opacity: 1;
    color: #a5b4fc;
}

.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

.logout-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radius-sm);
    color: #fca5a5;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s ease;
}

.logout-link svg {
    width: 18px;
    height: 18px;
}

.logout-link:hover {
    background: rgba(220, 38, 38, 0.12);
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar-title {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

.content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* ---------- Page headers ---------- */

.page-head {
    margin-bottom: 1.5rem;
}

.page-head p {
    margin: 0.15rem 0 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.page-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-head-row p {
    margin: 0;
}

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.75rem;
}

.card h2, .content h2 {
    font-size: 1.05rem;
    margin: 0 0 1rem;
}

.section-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 1rem;
    color: var(--text);
}

/* ---------- Stat tiles ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.4rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-faint);
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-card .stat-icon svg {
    width: 20px;
    height: 20px;
}

.stat-card.warn .stat-icon {
    background: #fff7ed;
    color: #c2410c;
}

.stat-card.warn .stat-value {
    color: #c2410c;
}

/* ---------- Dashboard quick actions ---------- */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
}

.dashboard-grid a {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.4rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.dashboard-grid a:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #d6d9f5;
}

.dashboard-grid .tile-icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--primary-light);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dashboard-grid .tile-icon svg {
    width: 21px;
    height: 21px;
}

/* ---------- Forms ---------- */

form label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text);
}

form .field {
    margin-bottom: 1.1rem;
}

form .hint {
    margin: 0.3rem 0 0;
    font-size: 0.8rem;
    color: var(--text-faint);
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    align-items: end;
}

.filter-bar .field {
    margin-bottom: 0;
}

.filter-actions {
    display: flex;
    gap: 0.6rem;
}

input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
    resize: vertical;
    min-height: 5rem;
}

input[readonly] {
    background: var(--surface-alt);
    color: var(--text-muted);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    letter-spacing: 0.03em;
    cursor: default;
}

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

button, .btn {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.65rem 1.35rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.15s ease, transform 0.05s ease;
}

button:hover, .btn:hover {
    background: var(--primary-dark);
}

button:active, .btn:active {
    transform: translateY(1px);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-alt);
}

/* ---------- Sale cart ---------- */

.sale-layout {
    display: grid;
    grid-template-columns: 3fr 7fr;
    gap: 1.5rem;
    align-items: start;
}

.sale-picker h2 {
    margin-bottom: 1rem;
}

.section-subtitle {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    margin: 1.25rem 0 0.6rem;
}

.section-subtitle:first-of-type {
    margin-top: 0.5rem;
}

.quick-item-row {
    display: flex;
    gap: 0.85rem;
    overflow-x: auto;
    padding: 0.15rem 0.15rem 0.6rem;
}

.quick-item {
    position: relative;
    flex: 0 0 auto;
    width: 148px;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 1rem 0.9rem 0.85rem;
    border-radius: var(--radius);
    background: linear-gradient(160deg, var(--primary-light), var(--surface));
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.quick-item:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.quick-item-rank {
    position: absolute;
    top: 0.6rem;
    right: 0.65rem;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--surface);
    border-radius: 999px;
    padding: 0.1rem 0.45rem;
    box-shadow: var(--shadow-sm);
}

.quick-item-name {
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.25;
    padding-right: 1.6rem;
}

.quick-item-meta {
    font-size: 0.74rem;
    color: var(--text-muted);
}

.quick-item-price {
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.95rem;
}

.quick-item-add {
    margin-top: 0.3rem;
    align-self: flex-start;
    padding: 0.32rem 0.75rem;
    font-size: 0.75rem;
}

.sale-picker .item-list {
    max-height: 420px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.item-row:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.item-row-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.item-row-name {
    font-weight: 600;
    font-size: 0.92rem;
}

.item-row-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.item-row-add {
    flex-shrink: 0;
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
}

.item-list-empty {
    text-align: center;
    color: var(--text-faint);
    padding: 1.5rem 0 0;
    margin: 0;
}

.sale-cart {
    position: sticky;
    top: 1.5rem;
}

.cart-empty {
    padding: 2rem 1rem;
}

.cart-empty svg {
    width: 34px;
    height: 34px;
}

.cart-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.cart-table th, .cart-table td {
    text-align: left;
    padding: 0.5rem 0.4rem;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.cart-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.cart-qty-input {
    width: 60px;
    padding: 0.35rem 0.5rem;
}

.cart-price-input {
    width: 80px;
    padding: 0.35rem 0.5rem;
}

.cart-remove-btn {
    background: transparent;
    color: var(--text-faint);
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
}

.cart-remove-btn:hover {
    color: var(--danger);
    background: transparent;
}

.cart-grand-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.cart-grand-total strong {
    font-size: 1.15rem;
}

.sale-cart button[type="submit"] {
    width: 100%;
    justify-content: center;
}

.sale-cart button[type="submit"]:disabled {
    background: var(--text-faint);
    cursor: not-allowed;
}

/* ---------- Tables ---------- */

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th, table td {
    text-align: left;
    padding: 0.85rem 1.25rem;
    font-size: 0.9rem;
}

table th {
    background: var(--surface-alt);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

table td {
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

table tbody tr:last-child td {
    border-bottom: none;
}

table tbody tr:hover {
    background: var(--surface-alt);
}

table td.empty-row {
    color: var(--text-faint);
    text-align: center;
    padding: 2rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-ok {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge-low {
    background: #fff7ed;
    color: #c2410c;
}

.low-stock {
    color: var(--danger);
    font-weight: 700;
}

.table-actions a {
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.pagination-controls {
    display: flex;
    gap: 0.6rem;
}

.pagination-controls span[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

.table-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
    font-size: 1rem;
}

.table-footer strong {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 1.2rem;
    box-shadow: var(--shadow-sm);
}

/* ---------- Flash messages ---------- */

.flash {
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.flash.success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-border);
}

.flash.error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error-border);
}

/* ---------- Empty states ---------- */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state svg {
    width: 42px;
    height: 42px;
    color: var(--text-faint);
    margin-bottom: 0.75rem;
}

.empty-state a {
    font-weight: 600;
}

/* ---------- Login page ---------- */

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at top left, #4f46e5 0%, #171a2b 55%, #0d0e19 100%);
    padding: 1.5rem;
}

.login-box {
    background: var(--surface);
    padding: 2.25rem 2.25rem 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 360px;
    animation: rise 0.35s ease;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-logo {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.login-logo svg {
    width: 24px;
    height: 24px;
    color: #fff;
}

.login-box h1 {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
}

.login-box .subtitle {
    margin: 0 0 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-box button {
    width: 100%;
    justify-content: center;
    padding: 0.7rem;
    margin-top: 0.25rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 820px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        padding: 0.75rem 1rem;
        overflow-x: auto;
    }

    .sidebar-brand {
        padding: 0.3rem 0.75rem 0.3rem 0;
    }

    .sidebar-nav {
        flex-direction: row;
        flex: none;
    }

    .sidebar-nav a span, .logout-link span {
        display: none;
    }

    .sidebar-footer {
        border-top: none;
        margin: 0;
        padding: 0;
        margin-left: auto;
    }

    .content, .topbar {
        padding: 1.25rem;
    }

    table {
        display: block;
        overflow-x: auto;
    }

    .sale-layout {
        grid-template-columns: 1fr;
    }

    .sale-cart {
        position: static;
    }
}
