:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(30, 41, 59, 0.8);
    --bg-input: rgba(15, 23, 42, 0.8);
    --bg-input-focus: rgba(15, 23, 42, 0.95);
    --border-subtle: rgba(148, 163, 184, 0.1);
    --border-focus: rgba(99, 102, 241, 0.5);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-indigo: #818cf8;
    --accent-indigo-glow: rgba(129, 140, 248, 0.3);
    --accent-emerald: #34d399;
    --accent-rose: #fb7185;
    --accent-amber: #fbbf24;
    --accent-sky: #38bdf8;
    --gradient-indigo: linear-gradient(135deg, #6366f1, #818cf8);
    --gradient-emerald: linear-gradient(135deg, #059669, #34d399);
    --gradient-rose: linear-gradient(135deg, #e11d48, #fb7185);
    --gradient-amber: linear-gradient(135deg, #d97706, #fbbf24);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow-indigo: 0 0 20px rgba(99, 102, 241, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: 'Inter', 'Noto Sans Thai', -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Ambient BG */
.ambient-bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.ambient-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.15; animation: float 20s ease-in-out infinite; }
.ambient-orb-1 { width: 600px; height: 600px; background: var(--accent-indigo); top: -200px; right: -100px; }
.ambient-orb-2 { width: 500px; height: 500px; background: var(--accent-emerald); bottom: -150px; left: -100px; animation-delay: -7s; }
.ambient-orb-3 { width: 400px; height: 400px; background: var(--accent-rose); top: 50%; left: 50%; transform: translate(-50%, -50%); animation-delay: -14s; }
@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(15px, 15px) scale(1.02); }
}

/* Glass Card */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
}

/* Layout */
.app-container { position: relative; z-index: 1; max-width: 1440px; margin: 0 auto; padding: 0 24px 48px; }

/* Header */
.app-header { padding: 24px 0 16px; }
.header-content { display: flex; justify-content: space-between; align-items: center; }
.logo-group { display: flex; align-items: center; gap: 16px; }
.logo-icon { width: 52px; height: 52px; background: var(--gradient-indigo); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; color: white; box-shadow: var(--shadow-glow-indigo); }
.app-header h1 { font-size: 1.75rem; font-weight: 800; background: linear-gradient(135deg, var(--text-primary), var(--accent-indigo)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.header-subtitle { font-size: 0.85rem; color: var(--text-muted); }

/* Summary Cards */
.summary-section { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.summary-card { background: var(--bg-card); backdrop-filter: blur(20px); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 20px; display: flex; align-items: center; gap: 16px; transition: all var(--transition-normal); position: relative; overflow: hidden; }
.summary-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.summary-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.summary-card--revenue::before { background: var(--gradient-indigo); }
.summary-card--cost::before { background: var(--gradient-rose); }
.summary-card--profit::before { background: var(--gradient-emerald); }
.summary-card--items::before { background: var(--gradient-amber); }
.summary-card__icon { width: 48px; height: 48px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.summary-card--revenue .summary-card__icon { background: rgba(99, 102, 241, 0.15); color: var(--accent-indigo); }
.summary-card--cost .summary-card__icon { background: rgba(251, 113, 133, 0.15); color: var(--accent-rose); }
.summary-card--profit .summary-card__icon { background: rgba(52, 211, 153, 0.15); color: var(--accent-emerald); }
.summary-card--items .summary-card__icon { background: rgba(251, 191, 36, 0.15); color: var(--accent-amber); }
.summary-card__content { display: flex; flex-direction: column; min-width: 0; }
.summary-card__label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.summary-card__value { font-size: 1.4rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==================== TABLE SECTION ==================== */
.table-section { padding: 28px; }
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.table-header h2 { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.table-header h2 svg { color: var(--accent-indigo); }
.table-actions { display: flex; align-items: center; gap: 12px; }

.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-input); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 8px 14px; transition: all var(--transition-fast); }
.search-box:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-indigo-glow); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input { background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 0.85rem; font-family: inherit; width: 180px; }
.search-box input::placeholder { color: var(--text-muted); }

.btn-add {
    display: flex; align-items: center; gap: 8px;
    background: var(--gradient-indigo); color: white; border: none;
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: all var(--transition-normal);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
    white-space: nowrap;
}
.btn-add:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35); }
.btn-add:active { transform: translateY(0); }

/* Table */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-md); }
.product-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.product-table thead th {
    padding: 12px 14px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(15, 23, 42, 0.5);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
.product-table tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}
.product-table tbody tr:hover { background: rgba(99, 102, 241, 0.04); }
.product-table tbody tr:last-child { border-bottom: none; }
.product-table td {
    padding: 14px;
    vertical-align: middle;
    white-space: nowrap;
    color: var(--text-secondary);
}
.product-table .td-name {
    font-weight: 600;
    color: var(--text-primary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.product-table .td-date { font-size: 0.8rem; color: var(--text-muted); }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* Profit badge in table */
.profit-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 700;
}
.profit-badge--positive { background: rgba(52, 211, 153, 0.12); color: var(--accent-emerald); }
.profit-badge--negative { background: rgba(251, 113, 133, 0.12); color: var(--accent-rose); }
.profit-badge--zero { background: rgba(148, 163, 184, 0.1); color: var(--text-muted); }

/* Sold badge */
.sold-badge { font-size: 0.82rem; color: var(--accent-sky); font-weight: 600; }

/* Action buttons in table */
.row-actions { display: flex; gap: 2px; justify-content: center; }
.btn-action {
    background: transparent; border: 1px solid transparent;
    padding: 6px; border-radius: var(--radius-sm);
    cursor: pointer; color: var(--text-muted);
    transition: all var(--transition-fast);
    display: flex; align-items: center; justify-content: center;
}
.btn-action:hover { color: var(--text-primary); background: rgba(148, 163, 184, 0.1); border-color: var(--border-subtle); }
.btn-action--delete:hover { color: var(--accent-rose); background: rgba(251, 113, 133, 0.08); border-color: rgba(251, 113, 133, 0.15); }

/* Empty State */
.empty-state { display: none; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--text-muted); text-align: center; }
.empty-state.visible { display: flex; }
.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state span { font-size: 0.85rem; }

/* ==================== MODAL ==================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    opacity: 0; visibility: hidden;
    transition: all var(--transition-normal);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 24px 0;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    padding: 32px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    transform: scale(0.9) translateY(10px);
    transition: transform var(--transition-normal);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: auto;
    flex-shrink: 0;
}
.modal-overlay.active .modal-content { transform: scale(1) translateY(0); }

/* Form modal - wider */
.modal-content--form {
    max-width: 720px;
    text-align: left;
}

.modal-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-subtle);
}
.modal-form-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}
.modal-form-header h3 svg { color: var(--accent-indigo); }

.btn-close-modal {
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition-fast);
}
.btn-close-modal:hover { background: rgba(148, 163, 184, 0.2); color: var(--text-primary); }

.modal-form-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}

/* Form inside modal */
.product-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group--wide { flex: 2; }
.form-group label { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input {
    background: var(--bg-input); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm); padding: 10px 12px;
    color: var(--text-primary); font-size: 0.9rem; font-family: inherit;
    transition: all var(--transition-fast); outline: none;
    width: 100%; max-width: 100%;
}
.form-group input::placeholder { color: var(--text-muted); }
.form-group input:focus { background: var(--bg-input-focus); border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-indigo-glow); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row--4 { grid-template-columns: repeat(4, 1fr); }

.form-divider { display: flex; align-items: center; gap: 12px; margin: 2px 0; }
.form-divider::before, .form-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-subtle); }
.form-divider span { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; }

.computed-value {
    padding: 10px 12px;
    background: rgba(251, 113, 133, 0.06);
    border: 1px solid rgba(251, 113, 133, 0.1);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-rose);
}
.computed-value--profit {
    background: rgba(52, 211, 153, 0.06);
    border-color: rgba(52, 211, 153, 0.1);
    color: var(--accent-emerald);
}

.btn-submit {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--gradient-indigo); color: white; border: none;
    padding: 12px 24px; border-radius: var(--radius-sm);
    font-size: 0.9rem; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: all var(--transition-normal);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}
.btn-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35); }
.btn-submit:active { transform: translateY(0); }

/* Delete modal */
.modal-icon { width: 72px; height: 72px; border-radius: 50%; background: rgba(251, 113, 133, 0.1); color: var(--accent-rose); display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; }
.modal-content h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; }
.modal-content p { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 4px; }
.modal-item-name { font-weight: 600; color: var(--text-secondary) !important; margin-bottom: 24px !important; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }
.btn-modal { padding: 10px 24px; border-radius: var(--radius-sm); font-size: 0.9rem; font-weight: 600; font-family: inherit; cursor: pointer; transition: all var(--transition-fast); border: none; }
.btn-modal--cancel { background: rgba(148, 163, 184, 0.1); color: var(--text-secondary); border: 1px solid var(--border-subtle); }
.btn-modal--cancel:hover { background: rgba(148, 163, 184, 0.2); }
.btn-modal--confirm { background: var(--gradient-rose); color: white; box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25); }
.btn-modal--confirm:hover { box-shadow: 0 6px 20px rgba(225, 29, 72, 0.35); transform: translateY(-1px); }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; z-index: 2000; opacity: 0; transform: translateY(20px) scale(0.95); visibility: hidden; transition: all var(--transition-normal); }
.toast.active { opacity: 1; transform: translateY(0) scale(1); visibility: visible; }
.toast-content { display: flex; align-items: center; gap: 10px; background: rgba(17, 24, 39, 0.95); backdrop-filter: blur(20px); border: 1px solid rgba(52, 211, 153, 0.2); color: var(--accent-emerald); padding: 14px 20px; border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 500; box-shadow: var(--shadow-lg); }

/* Loading */
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--text-muted); gap: 16px; }
.loading-spinner { width: 36px; height: 36px; border: 3px solid var(--border-subtle); border-top-color: var(--accent-indigo); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state p { font-size: 0.9rem; font-weight: 500; }
.api-notice { padding: 16px 20px; background: rgba(251, 191, 36, 0.08); border: 1px solid rgba(251, 191, 36, 0.2); border-radius: var(--radius-sm); color: var(--accent-amber); font-size: 0.85rem; line-height: 1.5; }

/* Responsive */
@media (max-width: 1024px) {
    .summary-section { grid-template-columns: repeat(2, 1fr); }
    .form-row--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    .app-container { padding: 0 12px 32px; }
    .summary-section { grid-template-columns: 1fr; }
    .form-row, .form-row--4 { grid-template-columns: 1fr; }
    .table-section { padding: 16px; }
    .table-header { flex-direction: column; align-items: flex-start; }
    .table-actions { width: 100%; flex-direction: column; }
    .search-box { width: 100%; }
    .search-box input { width: 100%; }
    .btn-add { width: 100%; justify-content: center; }
    .modal-overlay { padding: 16px 0; align-items: flex-start; }
    .modal-content { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
    .modal-content--form { padding: 20px; }
    .app-header h1 { font-size: 1.4rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 3px; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Login */
.login-overlay {
    position: fixed; inset: 0;
    background: var(--bg-primary);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden;
    transition: all var(--transition-normal);
}
.login-overlay.active { opacity: 1; visibility: visible; }
.login-card {
    padding: 40px;
    width: 90%; max-width: 400px;
    transform: translateY(20px);
    transition: transform var(--transition-normal);
}
.login-overlay.active .login-card { transform: translateY(0); }

/* Row animation */
@keyframes rowSlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}
.product-table tbody tr { animation: rowSlideIn 0.25s ease-out; }
