:root {
    color-scheme: light;
    --bg: #f1f5f9;
    --bg-accent: #e2e8f0;
    --surface: #ffffff;
    --surface-elevated: #f8fafc;
    --surface-muted: #f1f5f9;
    --text: #0f172a;
    --text-soft: #334155;
    --muted: #64748b;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-secondary: #f59e0b;
    --accent-soft: rgba(14, 165, 233, 0.12);
    --accent-ring: rgba(14, 165, 233, 0.25);
    --sidebar-bg: #0f172a;
    --sidebar-surface: #1e293b;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #e2e8f0;
    --sidebar-active-bg: rgba(14, 165, 233, 0.15);
    --sidebar-active-text: #38bdf8;
    --sidebar-icon-bg: rgba(255, 255, 255, 0.06);
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.14);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow: 0 16px 48px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 24px 64px rgba(15, 23, 42, 0.12);
    --radius-sm: 10px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "DM Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 0% 0%, rgba(14, 165, 233, 0.08), transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(245, 158, 11, 0.06), transparent 40%),
        var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Lucide icons */
[data-lucide] {
    width: 18px;
    height: 18px;
    stroke-width: 2;
    stroke: currentColor;
    flex-shrink: 0;
}

/* —— Auth pages —— */
.auth-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
}

.page-shell {
    width: min(440px, 100%);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    padding: 36px 32px;
}

.auth-card h1 {
    margin: 16px 0 8px;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.auth-card .brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.auth-card .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
}

.auth-card .brand-text {
    font-weight: 800;
    font-size: 1.1rem;
}

/* —— App shell —— */
.app-shell {
    display: grid;
    grid-template-columns: 272px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #0c1222 100%);
    border-right: 1px solid var(--sidebar-border);
    padding: 28px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 4px 8px;
}

.sidebar .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-secondary) 100%);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.4);
}

.sidebar .brand-text {
    font-size: 1.05rem;
    font-weight: 800;
    margin-bottom: 2px;
    letter-spacing: -0.02em;
    color: #f8fafc;
}

.brand-subtitle {
    color: var(--sidebar-text);
    font-size: 0.82rem;
    margin: 0;
}

.sidebar-user {
    color: var(--sidebar-text);
    font-size: 0.82rem;
    margin: 0;
}

.sidebar-nav {
    display: grid;
    gap: 20px;
    flex: 1;
}

.nav-section {
    display: grid;
    gap: 4px;
}

.nav-section-label {
    margin: 0 0 6px 12px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #64748b;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    border: 1px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-link-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--sidebar-icon-bg);
    flex-shrink: 0;
}

.sidebar-link-icon [data-lucide] {
    width: 17px;
    height: 17px;
    color: var(--sidebar-text);
    stroke: currentColor;
}

.sidebar-link:hover {
    background: var(--sidebar-surface);
    color: var(--sidebar-text-hover);
}

.sidebar-link:hover .sidebar-link-icon {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-link:hover .sidebar-link-icon [data-lucide] {
    color: var(--sidebar-text-hover);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    border-color: rgba(56, 189, 248, 0.25);
    color: var(--sidebar-active-text);
}

.sidebar-link.active .sidebar-link-icon {
    background: var(--accent);
}

.sidebar-link.active .sidebar-link-icon [data-lucide] {
    color: #fff;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-email {
    color: #f1f5f9;
    font-weight: 600;
    font-size: 0.9rem;
    word-break: break-word;
}

.sidebar-logout {
    background: var(--sidebar-surface) !important;
    border: 1px solid var(--sidebar-border);
    box-shadow: none !important;
}

.sidebar-logout:hover {
    background: #334155 !important;
    border-color: rgba(255, 255, 255, 0.12);
}

.logout-form {
    margin: 0;
}

.sidebar-logout {
    width: 100%;
}

.main-content {
    padding: 32px 40px 48px;
    max-width: 1400px;
}

.page-top {
    margin-bottom: 28px;
}

.page-badge {
    margin: 0 0 8px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-soft);
}

.page-top h1 {
    margin: 0;
    font-size: clamp(1.75rem, 2.2vw, 2.35rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

/* —— Cards & panels —— */
.content-card,
.card,
.users-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
}

.content-card {
    padding: 28px 32px;
}

.content-card h2,
.users-panel h3 {
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-heading {
    margin-bottom: 24px;
}

.page-heading .subtitle {
    margin-top: 6px;
}

p.subtitle {
    margin: 0;
    color: var(--muted);
    line-height: 1.65;
    font-size: 0.95rem;
}

/* —— Dashboard —— */
.dashboard-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    margin-bottom: 24px;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 22px 24px;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    opacity: 0.12;
    transform: translate(30%, -30%);
}

.stat-card--users::before { background: #0ea5e9; }
.stat-card--items::before { background: #14b8a6; }
.stat-card--products::before { background: #8b5cf6; }
.stat-card--stock::before { background: #22c55e; }
.stat-card--vendors::before { background: #f59e0b; }
.stat-card--parties::before { background: #f43f5e; }

.stat-card__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    margin-bottom: 4px;
}

.stat-card__icon [data-lucide] {
    width: 22px;
    height: 22px;
}

.stat-card--users .stat-card__icon { background: #e0f2fe; color: #0284c7; }
.stat-card--items .stat-card__icon { background: #ccfbf1; color: #0d9488; }
.stat-card--products .stat-card__icon { background: #ede9fe; color: #7c3aed; }
.stat-card--stock .stat-card__icon { background: #dcfce7; color: #16a34a; }
.stat-card--vendors .stat-card__icon { background: #fef3c7; color: #d97706; }
.stat-card--parties .stat-card__icon { background: #ffe4e6; color: #e11d48; }

.card-title,
.stat-card__label {
    margin: 0;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-size: 0.75rem;
    font-weight: 700;
}

.card-value,
.stat-card__value {
    margin: 0;
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.quick-links {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    margin-top: 20px;
}

.quick-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    color: var(--text-soft);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.quick-link [data-lucide] {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

.quick-link:hover {
    border-color: rgba(14, 165, 233, 0.35);
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.card {
    padding: 24px;
    min-height: 150px;
    display: grid;
    gap: 16px;
}

.placeholder-block,
.empty-state {
    border: 1px dashed rgba(14, 165, 233, 0.3);
    padding: 40px 24px;
    border-radius: var(--radius-lg);
    color: var(--muted);
    background: linear-gradient(180deg, rgba(14, 165, 233, 0.04), transparent);
    text-align: center;
}

.empty-state__title {
    margin: 0 0 8px;
    font-weight: 700;
    color: var(--text-soft);
    font-size: 1rem;
}

.empty-state__hint {
    margin: 0;
    font-size: 0.9rem;
}

/* —— Toolbar & tables —— */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.toolbar strong {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

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

.table-wrap {
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.data-table th,
.data-table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table thead th {
    text-align: left;
    color: var(--muted);
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--surface-elevated);
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background 0.12s ease;
}

.data-table tbody tr:hover {
    background: rgba(14, 165, 233, 0.04);
}

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

.data-table .empty-row td {
    text-align: center;
    color: var(--muted);
    padding: 32px;
    font-style: italic;
}

.text-right {
    text-align: right;
}

.actions-cell {
    white-space: nowrap;
}

.action-link,
.action-delete {
    border: none;
    background: none;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.12s ease;
}

.action-link:hover,
.action-delete:hover {
    background: var(--accent-soft);
    text-decoration: none;
}

.action-delete {
    color: var(--danger);
}

.action-delete:hover {
    background: var(--danger-bg);
}

.action-form {
    display: inline;
    margin: 0;
}

/* —— Forms —— */
.form-panel {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    margin-bottom: 24px;
}

.form-panel__title {
    margin: 0 0 4px;
    font-weight: 700;
    font-size: 0.95rem;
}

.form-panel .subtitle {
    margin-bottom: 16px;
    font-size: 0.88rem;
}

.inline-form-grid {
    display: grid;
    grid-template-columns: 1fr minmax(140px, 180px) auto;
    gap: 14px;
    align-items: end;
}

.form-group {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.form-group label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-soft);
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

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

textarea {
    min-height: 96px;
    resize: vertical;
}

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

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* —— Buttons —— */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.94rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    text-decoration: none;
}

.btn-primary,
button[type="submit"]:not(.action-delete):not(.sidebar-logout):not(.remove-product-item-row) {
    background: linear-gradient(180deg, #38bdf8, var(--accent));
    color: #fff;
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
}

.btn-primary:hover,
button[type="submit"]:not(.action-delete):not(.sidebar-logout):not(.remove-product-item-row):hover {
    background: linear-gradient(180deg, var(--accent), var(--accent-hover));
    transform: translateY(-1px);
}

.btn-ghost,
button.meta {
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    width: auto;
    margin-top: 0;
    padding: 10px 14px;
}

.btn-ghost:hover,
button.meta:hover {
    background: var(--surface-muted);
    color: var(--text);
    transform: none;
}

.add-button {
    width: auto;
    margin-top: 0;
    white-space: nowrap;
}

.add-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.modal-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 8px;
}

.modal-actions .btn-primary,
.modal-actions button[type="submit"] {
    width: auto;
    min-width: 140px;
}

/* —— Alerts —— */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.92rem;
    font-weight: 500;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-error {
    background: var(--danger-bg);
    color: #991b1b;
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.alert-success {
    background: var(--success-bg);
    color: #047857;
    border: 1px solid rgba(5, 150, 105, 0.2);
}

.alert ul {
    margin: 0;
    padding-left: 18px;
}

/* —— Modal —— */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    padding: 20px;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: min(640px, 100%);
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.modal-wide {
    width: min(760px, 100%);
}

.modal-header {
    padding: 22px 24px 0;
}

.modal-header h3 {
    margin: 0 0 6px;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.modal-body {
    padding: 16px 24px 24px;
}

.modal .form-group {
    margin-bottom: 14px;
}

.product-item-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.product-item-row {
    display: grid;
    grid-template-columns: 1fr 110px auto;
    gap: 10px;
    align-items: center;
}

.product-item-row select,
.product-item-row .product-item-qty {
    margin: 0;
}

.btn-add-row {
    margin-top: 10px;
    width: auto;
    padding: 10px 14px;
    background: var(--surface-elevated);
    color: var(--accent);
    border: 1px dashed rgba(14, 165, 233, 0.4);
    box-shadow: none;
}

.btn-add-row:hover {
    background: var(--accent-soft);
    transform: none;
}

.product-item-row .remove-product-item-row {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    background: transparent;
    color: var(--danger);
    box-shadow: none;
    font-weight: 600;
    font-size: 0.85rem;
}

.product-item-row .remove-product-item-row:hover {
    background: var(--danger-bg);
    transform: none;
}

.sell-product-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sell-product-row {
    display: grid;
    grid-template-columns: 1fr 100px 80px auto;
    gap: 10px;
    align-items: center;
}

.sell-product-row select,
.sell-product-row .sell-qty {
    margin: 0;
}

.sell-line-total {
    font-weight: 700;
    color: var(--text);
    font-size: 0.95rem;
    text-align: right;
}

.sell-product-row .remove-sell-product-row {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    background: transparent;
    color: var(--danger);
    box-shadow: none;
    font-weight: 600;
    font-size: 0.85rem;
}

@media (max-width: 720px) {
    .sell-product-row {
        grid-template-columns: 1fr;
    }
    .sell-line-total {
        text-align: left;
    }
}

/* —— Users page —— */
.users-grid {
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    margin-top: 8px;
}

.users-panel {
    padding: 24px;
}

.users-panel h3 {
    margin-top: 0;
    margin-bottom: 18px;
}

.users-table-panel .table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.profile-form {
    max-width: 480px;
}

.meta {
    margin-top: 16px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: left;
}

.meta a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.meta a:hover {
    text-decoration: underline;
}

h1 {
    margin: 0;
}

/* —— Responsive —— */
@media (max-width: 1100px) {
    .users-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: column;
        padding: 20px;
    }

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

    .nav-section {
        display: contents;
    }

    .nav-section-label {
        grid-column: 1 / -1;
        margin: 12px 0 4px;
    }

    .main-content {
        padding: 24px 20px 40px;
    }

    .inline-form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 620px) {
    .content-card {
        padding: 20px 18px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .form-row-2 {
        grid-template-columns: 1fr;
    }

    .product-item-row {
        grid-template-columns: 1fr;
    }

    .data-table th,
    .data-table td {
        padding: 12px 14px;
    }
}
