/* =====================================================================
   style.css - Serialized Inventory POS
   Professional dark theme, CSS custom properties, no frameworks.
   ===================================================================== */

:root {
    --bg-primary:      #0f1115;
    --bg-panel:        #171a21;
    --bg-panel-alt:    #1e222b;
    --bg-input:        #12151b;
    --border-subtle:   #2a2f3a;
    --border-focus:    #4f8cff;

    --text-primary:    #e8eaed;
    --text-secondary:  #9aa3b2;
    --text-muted:      #626a78;

    --accent:          #4f8cff;
    --accent-hover:    #3d78e8;
    --accent-soft:     rgba(79, 140, 255, 0.12);

    --status-available: #34d399;
    --status-reserved:  #fbbf24;
    --status-sold:      #f87171;

    --success: #34d399;
    --danger:  #f87171;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-panel: 0 4px 24px rgba(0, 0, 0, 0.35);

    font-size: 16px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
    line-height: 1.5;
    min-height: 100vh;
}

/* ---------------------------- Layout ------------------------------ */

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
}

.topbar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.topbar__brand-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.main-grid {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(340px, 480px) 1fr;
    gap: 20px;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }
}

/* ---------------------------- Panels ------------------------------- */

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-panel);
}

.panel + .panel { margin-top: 20px; }

.panel__title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.panel__title .count-badge {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
}

/* ---------------------------- Form fields --------------------------- */

label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.field { margin-bottom: 16px; }

input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 11px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

select:disabled,
input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

select {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* ---------------------------- Buttons ------------------------------- */

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 11px 18px;
    transition: background 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}

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

.btn-primary {
    background: var(--accent);
    color: #ffffff;
    width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
    background: var(--bg-panel-alt);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-success {
    background: var(--success);
    color: #06231a;
}
.btn-success:hover { opacity: 0.88; }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 6px 12px;
    font-size: 0.78rem;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}

/* ---------------------------- Price badge --------------------------- */

.price-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.05rem;
    margin-top: 4px;
}

.price-badge__label {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* ---------------------------- Cart list ------------------------------ */

.cart-list {
    list-style: none;
    margin: 0 0 16px;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.cart-list:empty::after {
    content: "No items added yet.";
    display: block;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.cart-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.88rem;
}
.cart-item:last-child { border-bottom: none; }

.cart-item__serial { font-weight: 600; }
.cart-item__price { color: var(--text-secondary); margin-left: auto; margin-right: 12px; }

.cart-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 4px;
    font-size: 1rem;
    border-top: 1px solid var(--border-subtle);
    margin-top: -1px;
    margin-bottom: 16px;
}
.cart-total__value { font-weight: 700; font-size: 1.2rem; color: var(--accent); }

/* ---------------------------- Status pills ---------------------------- */

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.pill--available { background: rgba(52, 211, 153, 0.15); color: var(--status-available); }
.pill--processing { background: rgba(251, 191, 36, 0.15); color: var(--status-reserved); }
.pill--won { background: rgba(52, 211, 153, 0.15); color: var(--status-available); }
.pill--expired { background: rgba(248, 113, 113, 0.15); color: var(--status-sold); }

/* ---------------------------- Quotations table ------------------------ */

.quote-row {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.88rem;
}
.quote-row:last-child { border-bottom: none; }
.quote-row__customer { font-weight: 600; }
.quote-row__meta { color: var(--text-muted); font-size: 0.78rem; }
.quote-row__actions { display: flex; gap: 8px; }

/* ---------------------------- Toasts --------------------------------- */

#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background: var(--bg-panel-alt);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    max-width: 320px;
    box-shadow: var(--shadow-panel);
    animation: toast-in 0.2s ease;
}
.toast--success { border-left-color: var(--success); }
.toast--error { border-left-color: var(--danger); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

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

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-panel);
}

.login-card h1 {
    font-size: 1.15rem;
    margin: 0 0 4px;
}
.login-card p.subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0 0 24px;
}

.error-text {
    color: var(--danger);
    font-size: 0.82rem;
    margin-top: 10px;
    min-height: 1em;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 24px 10px;
}

/* ---------------------------- Tab navigation --------------------------- */

.tabbar {
    display: flex;
    gap: 4px;
    flex: 1;
    justify-content: center;
    flex-wrap: wrap;
}

.tab-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.view-container {
    flex: 1;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
}

.tab-view { display: none; }
.tab-view.active { display: block; }

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.view-header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0;
}
.view-header__actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filter-select {
    width: auto;
    min-width: 160px;
    padding: 8px 32px 8px 12px;
}

/* ---------------------------- Card grid (catalog) ----------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
}

.product-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s ease;
}
.product-card:hover { border-color: var(--accent); }

.product-card__image {
    width: 100%;
    height: 140px;
    background: var(--bg-panel-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    overflow: hidden;
}
.product-card__image img { width: 100%; height: 100%; object-fit: cover; }

.product-card__body { padding: 14px; }
.product-card__name { font-weight: 600; margin-bottom: 4px; font-size: 0.95rem; }
.product-card__meta { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 10px; }
.product-card__price { font-weight: 700; color: var(--accent); font-size: 1.05rem; margin-bottom: 8px; }

.stock-row { display: flex; gap: 8px; flex-wrap: wrap; font-size: 0.72rem; }
.stock-chip {
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 700;
}
.stock-chip--available { background: rgba(52, 211, 153, 0.15); color: var(--status-available); }
.stock-chip--reserved { background: rgba(251, 191, 36, 0.15); color: var(--status-reserved); }
.stock-chip--sold { background: rgba(248, 113, 113, 0.15); color: var(--status-sold); }

/* ---------------------------- Data tables ------------------------------ */

.table-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-panel);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87rem;
}
.data-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg-panel-alt);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border-subtle);
}
.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-panel-alt); }
.data-table .row-link { cursor: pointer; }

.data-table td.actions-cell {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ---------------------------- Modal ------------------------------------- */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 500;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 640px;
    box-shadow: var(--shadow-panel);
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-subtle);
}
.modal__header h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.modal__close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
    padding: 4px 8px;
}
.modal__close:hover { color: var(--text-primary); }

.modal__body {
    padding: 22px;
    overflow-y: auto;
}

/* Form helper layouts inside modals */
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

.line-item-row {
    display: grid;
    grid-template-columns: 2fr 80px 110px auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 10px;
}
.line-item-row .field { margin-bottom: 0; }

.service-row {
    display: grid;
    grid-template-columns: 2fr 120px auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 10px;
}
.service-row .field { margin-bottom: 0; }

.remove-line-btn {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--danger);
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
}
.remove-line-btn:hover { border-color: var(--danger); }

.detail-section { margin-bottom: 20px; }
.detail-section h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    margin: 0 0 10px;
}
.detail-line {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.88rem;
}
.detail-line:last-child { border-bottom: none; }
.detail-line__meta { color: var(--text-muted); font-size: 0.76rem; }

.grand-total {
    display: flex;
    justify-content: space-between;
    padding-top: 14px;
    margin-top: 6px;
    border-top: 1px solid var(--border-subtle);
    font-size: 1.05rem;
    font-weight: 700;
}
.grand-total__value { color: var(--accent); }

.text-muted { color: var(--text-muted); }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }

textarea {
    width: 100%;
    padding: 11px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
}
textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
    width: 100%;
    padding: 9px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* =====================================================================
   RESPONSIVE / MOBILE
   ===================================================================== */

/* Tables need a scroll wrapper on small screens rather than squeezing. */
.table-panel {
    overflow-x: auto;
}
.data-table {
    min-width: 560px;
}

@media (max-width: 900px) {
    .main-grid { grid-template-columns: 1fr; }

    .view-container { padding: 16px; }

    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }
}

@media (max-width: 760px) {
    .topbar {
        gap: 10px;
        padding: 12px 16px;
    }
    .topbar__user span#user-name { display: none; } /* saves space; shown in sidebar instead */

    /* Inline tabbar and its actions are replaced by the sidebar on mobile. */
    .tabbar { display: none; }
    .topbar__user .btn-secondary#company-settings-btn { display: none; }

    .view-header {
        flex-direction: column;
        align-items: stretch;
    }
    .view-header__actions {
        flex-wrap: wrap;
    }
    .view-header__actions .filter-select,
    .view-header__actions button {
        flex: 1 1 auto;
    }

    .modal-overlay { padding: 0; align-items: stretch; }
    .modal {
        max-width: 100%;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .form-row { flex-direction: column; gap: 0; }

    .line-item-row {
        grid-template-columns: 1fr;
        gap: 6px;
        padding-bottom: 12px;
        margin-bottom: 14px;
        border-bottom: 1px solid var(--border-subtle);
    }
    .line-item-row .remove-line-btn {
        justify-self: end;
        width: auto;
        padding: 6px 14px;
    }

    .service-row {
        grid-template-columns: 1fr;
        gap: 6px;
        padding-bottom: 12px;
        margin-bottom: 14px;
        border-bottom: 1px solid var(--border-subtle);
    }
    .service-row .remove-line-btn {
        justify-self: end;
        width: auto;
        padding: 6px 14px;
    }
}

/* ---------------------------- Hamburger + mobile sidebar ---------------- */

.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    width: 38px;
    height: 38px;
    padding: 0;
    flex-shrink: 0;
}
.hamburger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    margin: 0 auto;
    border-radius: 2px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 600;
}
.sidebar-overlay.open { display: block; }

.mobile-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 82vw;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    z-index: 601;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-panel);
}
.mobile-sidebar.open { transform: translateX(0); }

.mobile-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.mobile-sidebar__nav {
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 2px;
    overflow-y: auto;
}

.sidebar-tab-btn {
    text-align: left;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 600;
}
.sidebar-tab-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.mobile-sidebar__footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--border-subtle);
}
.mobile-sidebar__user {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

@media (max-width: 760px) {
    .hamburger-btn { display: flex; }
}

@media (max-width: 480px) {
    :root { font-size: 15px; }

    .card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .product-card__image { height: 100px; }
    .product-card__body { padding: 10px; }

    .login-card { padding: 24px 20px; }

    #toast-container {
        left: 12px;
        right: 12px;
        top: 12px;
    }
    .toast { max-width: 100%; }
}
