:root {
    --bg: #f1f5f9;
    --bg-accent: #e0f2f1;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --primary-light: #14b8a6;
    --border: #e2e8f0;
    --border-soft: #f1f5f9;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --success: #059669;
    --success-bg: #ecfdf5;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 8px 24px rgba(15, 118, 110, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 118, 110, 0.12);
    --radius: 16px;
    --radius-lg: 20px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body.page-app {
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(20, 184, 166, 0.15), transparent),
        linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
}

body.page-auth {
    background:
        radial-gradient(circle at 20% 20%, rgba(20, 184, 166, 0.2), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(13, 148, 136, 0.15), transparent 40%),
        linear-gradient(160deg, #ecfdf5 0%, #f8fafc 50%, #e2e8f0 100%);
}

body.page-stockist .topbar-logo,
body.page-stockist .badge-ai {
    background: linear-gradient(135deg, #0369a1, #0d9488);
}

body.page-admin .topbar-logo {
    background: linear-gradient(135deg, #475569, #64748b);
}

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

.container {
    width: min(100%, 720px);
    margin: 0 auto;
    padding: 16px 16px 32px;
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-logo {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: white;
    font-size: 1.1rem;
    font-weight: 800;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.topbar h1 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eyebrow {
    margin: 0 0 2px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
    font-weight: 700;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.card-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--bg-accent);
    color: var(--primary-dark);
    font-size: 1rem;
}

.card-icon-search {
    font-size: 1.1rem;
    font-weight: 700;
}

.card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.calculator-card {
    border-color: rgba(13, 148, 136, 0.2);
    background: linear-gradient(180deg, #ffffff 0%, #f8fffe 100%);
}

.calc-intro {
    margin-bottom: 10px;
}

.calc-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.calc-examples-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chip {
    border: 1px solid rgba(13, 148, 136, 0.25);
    background: #ecfdf5;
    color: var(--primary-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.chip:hover {
    background: #d1fae5;
    border-color: var(--primary-light);
}

.chip:active {
    transform: scale(0.97);
}

.search-card {
    padding-bottom: 14px;
}

.hint {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.55;
}

.hint:last-child {
    margin-bottom: 0;
}

.hint code {
    background: #ecfdf5;
    color: var(--primary-dark);
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
}

.search-hint,
.table-legend {
    margin-top: 10px;
    margin-bottom: 0;
    font-size: 0.8rem;
}

.badge,
.count-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.count-badge {
    background: var(--border-soft);
    color: var(--text-muted);
}

.badge-ai {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: white;
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.3);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.btn-primary:hover {
    box-shadow: 0 6px 18px rgba(13, 148, 136, 0.45);
}

.btn-secondary {
    background: #ecfdf5;
    color: var(--primary-dark);
}

.btn-ghost {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 8px 14px;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.82rem;
}

.btn-block {
    width: 100%;
}

/* Inputs */
.input-wrap {
    position: relative;
    width: 100%;
}

.input-wrap input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: #f8fafc;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.input-wrap input::placeholder {
    color: #94a3b8;
}

.input-wrap input:focus {
    outline: none;
    border-color: var(--primary-light);
    background: var(--surface);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
}

.auth-form label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
}

.auth-form {
    display: grid;
    gap: 14px;
}

/* Forms layout */
.search-form,
.calc-form,
.upload-form {
    display: grid;
    gap: 10px;
}

.search-form-live,
.calc-form .input-wrap {
    grid-column: 1 / -1;
}

@media (min-width: 560px) {
    .calc-form {
        grid-template-columns: 1fr auto;
        align-items: stretch;
    }

    .calc-form .btn-primary {
        min-width: 100px;
        padding-top: 14px;
        padding-bottom: 14px;
    }
}

/* Auth */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    gap: 16px;
}

.auth-card {
    width: min(100%, 400px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 28px 24px;
    box-shadow: var(--shadow-lg);
}

.brand {
    text-align: center;
    margin-bottom: 24px;
}

.brand-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: white;
    font-size: 1.75rem;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(13, 148, 136, 0.35);
}

.brand h1 {
    margin: 0 0 8px;
    font-size: 1.5rem;
    font-weight: 800;
}

.brand p {
    margin: 0 0 6px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.role-list {
    list-style: none;
    margin: 20px 0 0;
    padding: 16px 0 0;
    border-top: 1px solid var(--border-soft);
    display: grid;
    gap: 10px;
}

.role-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.role-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.role-mitra {
    background: var(--primary);
}

.role-stockist {
    background: #0369a1;
}

.role-admin {
    background: #64748b;
}

.auth-footer-note {
    margin: 0;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
}

/* Alerts */
.alert {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #a7f3d0;
}

.is-hidden {
    display: none !important;
}

#products-panel.is-loading #products-table-wrap {
    opacity: 0.5;
    pointer-events: none;
}

/* Calculator results */
#calc-result {
    margin-top: 4px;
}

#calc-result .hint {
    padding: 12px 0;
    text-align: center;
}

.calc-breakdown {
    margin-top: 14px;
    display: grid;
    gap: 8px;
}

.calc-row {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.calc-row-main {
    margin-bottom: 10px;
}

.calc-row-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.calc-row-title strong {
    font-size: 0.95rem;
    color: var(--primary-dark);
}

.calc-qty {
    font-size: 0.82rem;
    font-weight: 800;
    color: white;
    background: var(--primary);
    padding: 3px 9px;
    border-radius: 8px;
}

.calc-row-name {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.calc-prices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 0.88rem;
    font-weight: 600;
}

.calc-prices em {
    font-style: normal;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-right: 4px;
}

.calc-total {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 6px;
}

.calc-total div {
    background: linear-gradient(145deg, var(--primary-dark), var(--primary));
    color: white;
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.25);
}

.calc-total span {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.88;
    margin-bottom: 4px;
}

.calc-total strong {
    font-size: 1.05rem;
    font-weight: 800;
}

/* Table */
.table-card {
    padding-bottom: 16px;
}

.table-scroll {
    margin: 0 -4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 560px;
    font-size: 0.86rem;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border-soft);
}

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

.data-table tbody tr:nth-child(even) td {
    background: #fafbfc;
}

.data-table tbody tr:hover td {
    background: #f0fdfa;
}

.data-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f1f5f9;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 700;
}

.data-table td:first-child {
    color: var(--text-muted);
    font-weight: 600;
    width: 40px;
}

.data-table td:nth-child(2) strong {
    color: var(--primary-dark);
    font-size: 0.88rem;
}

.data-table td.price {
    white-space: nowrap;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.data-table td:last-child {
    color: var(--text-muted);
    line-height: 1.4;
    max-width: 200px;
}

.empty-state {
    text-align: center;
    padding: 32px 16px;
}

.empty-state p {
    margin: 0 0 8px;
    color: var(--text-muted);
}

/* Admin */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat {
    background: linear-gradient(180deg, #f8fafc, #fff);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
}

.stat span {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 6px;
}

.stat strong {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.upload-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.upload-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-soft);
}

.upload-list li:last-child {
    border-bottom: none;
}

.upload-list span,
.upload-list time {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.file-label {
    display: grid;
    gap: 8px;
    padding: 18px;
    border: 2px dashed #cbd5e1;
    border-radius: 14px;
    text-align: center;
    cursor: pointer;
    background: #f8fafc;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.file-label:hover {
    border-color: var(--primary-light);
    background: #ecfdf5;
}

.upload-form-multi {
    display: grid;
    gap: 12px;
}

@media (min-width: 768px) {
    .container {
        padding: 20px 24px 40px;
    }

    .topbar {
        padding: 16px 24px;
    }

    .topbar h1 {
        font-size: 1.2rem;
    }

    .card {
        padding: 22px;
        margin-bottom: 16px;
    }

    .card-header h2 {
        font-size: 1.12rem;
    }
}
