:root {
    --bg-color: #f5f6f8;
    --surface-color: #ffffff;
    --sidebar-bg: #1e2a3a;
    --sidebar-hover: #2a3b52;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }

a {
    color: var(--accent-color);
    text-decoration: none;
}

/* Layout */
.layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 20px 24px;
    background-color: rgba(0, 0, 0, 0.2);
}

.sidebar-brand h2 {
    color: #fff;
    margin-bottom: 4px;
    font-size: 1.25rem;
}

.sidebar-brand small {
    color: var(--sidebar-text);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    color: var(--sidebar-text);
    transition: all 0.2s;
    font-weight: 500;
}

.sidebar-nav a i {
    margin-right: 12px;
    width: 20px;
    height: 20px;
}

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

.sidebar-nav a.active {
    background-color: rgba(37, 99, 235, 0.1);
    color: var(--accent-color);
    border-right: 3px solid var(--accent-color);
}

.sidebar-footer {
    padding: 16px 24px;
    background-color: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background-color: var(--accent-color);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    margin-right: 12px;
}

.user-name {
    color: #fff;
    font-weight: 500;
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
}

.btn-logout {
    width: 100%;
    background: transparent;
    border: 1px solid var(--sidebar-text);
    color: var(--sidebar-text);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8125rem;
    transition: all 0.2s;
}

.btn-logout:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Important for flex child truncation */
}

.topbar {
    height: 64px;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
}

.sidebar-toggle {
    display: none;
    margin-right: 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
}

.topbar-right {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.page-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* Cards */
.card {
    background-color: var(--surface-color);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 20px;
}

/* Stats Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

.stat-title {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Tables */
.table-responsive {
    overflow-x: auto;
}

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

th {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: #f9fafb;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

tbody tr:hover {
    background-color: #f9fafb;
}

tbody tr.low-stock {
    background-color: #fefce8;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.2;
}

.btn i {
    width: 16px;
    height: 16px;
    margin-right: 8px;
}

.btn-primary {
    background-color: var(--accent-color);
    color: #fff;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: #fff;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #f9fafb;
}

.btn-danger {
    background-color: var(--danger-color);
    color: #fff;
}

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

.btn-icon {
    padding: 6px;
}

.btn-icon i {
    margin-right: 0;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background-color: #f3f4f6;
    color: var(--text-primary);
}
.btn-ghost.text-danger:hover {
    color: var(--danger-color);
    background-color: #fef2f2;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 1rem;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    font-family: inherit;
}

.form-control:focus {
    outline: 0;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.input-group {
    display: flex;
}

.input-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-left: -1px;
}

/* Billing Grid */
.billing-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.billing-main {
    flex: 1;
    min-width: 0;
}

.billing-sidebar {
    width: 340px;
    flex-shrink: 0;
}

.search-barcode-box {
    margin-bottom: 20px;
    position: relative;
}

.search-barcode-box .icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-barcode-box .form-control {
    padding-left: 40px;
    height: 48px;
    font-size: 1rem;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: var(--shadow-md);
    z-index: 10;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}
.search-results.show {
    display: block;
}

.search-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-item:last-child {
    border-bottom: none;
}
.search-item:hover {
    background-color: #f9fafb;
}

.cart-qty-input {
    width: 60px;
    text-align: center;
    padding: 4px;
    height: 28px;
}

.totals-box {
    background-color: #f8fafc;
    border-top: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 0 0 8px 8px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 1rem;
}

.total-row.grand-total {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--success-color);
    margin-bottom: 20px;
    border-top: 2px dashed var(--border-color);
    padding-top: 12px;
}

/* Manual Item Toggle */
.manual-item-form {
    background: #f9fafb;
    padding: 16px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    display: none;
}
.manual-item-form.show {
    display: block;
}
.manual-item-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}
.manual-item-row > div {
    flex: 1;
}
.manual-item-row > div:first-child {
    flex: 2;
}
.manual-item-row > div:last-child {
    flex: 0;
}

.badge {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 4px;
    background-color: #e5e7eb;
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background-color: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 9999;
    font-weight: 500;
}
.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(-10px);
}
.toast-success { background-color: var(--success-color); }
.toast-error { background-color: var(--danger-color); }

/* Login Page */
.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-color);
}
.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}
.login-header {
    text-align: center;
    margin-bottom: 32px;
}
.login-header h1 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

/* Receipt Display (HTML) */
.receipt-container {
    max-width: 300px;
    margin: 0 auto;
    background: #fff;
    padding: 20px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.receipt {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    color: #000;
    line-height: 1.4;
    width: 220px; /* ~58mm equivalent */
    margin: 0 auto;
}
.receipt-header {
    text-align: center;
    margin-bottom: 10px;
}
.receipt-header h2 {
    font-size: 16px;
    margin: 0;
}
.receipt-divider {
    border-top: 1px dashed #000;
    margin: 8px 0;
}
.receipt table {
    width: 100%;
}
.receipt th, .receipt td {
    padding: 2px 0;
    border: none;
    font-size: 12px;
    color: #000;
    background: transparent;
    text-transform: none;
    letter-spacing: normal;
}
.receipt th {
    font-weight: bold;
}
.receipt td.num {
    text-align: right;
}
.receipt-footer {
    text-align: center;
    margin-top: 10px;
}
.receipt-total {
    font-weight: bold;
    font-size: 14px;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-backdrop.show {
    display: flex;
}
.modal-content {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-body {
    padding: 20px;
}
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Responsive */
@media (max-width: 1024px) {
    .billing-layout {
        flex-direction: column;
    }
    .billing-sidebar {
        width: 100%;
    }
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: 100;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-toggle {
        display: block;
    }
}
