:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #000000);
    --hint: var(--tg-theme-hint-color, #999999);
    --link: var(--tg-theme-link-color, #2678b6);
    --btn: var(--tg-theme-button-color, #2678b6);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
    --section-bg: var(--tg-theme-section-bg-color, var(--secondary-bg));
    --divider: rgba(128, 128, 128, 0.15);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    padding: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 100%;
    padding: 12px;
}

/* Header */
header {
    margin-bottom: 12px;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

h1 {
    font-size: 20px;
    font-weight: 700;
}

.user-badge {
    font-size: 12px;
    color: var(--hint);
    background: var(--secondary-bg);
    padding: 4px 10px;
    border-radius: 20px;
}

.brand-selector select {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius);
    background: var(--secondary-bg);
    color: var(--text);
    font-size: 14px;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    cursor: pointer;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    background: var(--secondary-bg);
    border-radius: var(--radius);
    padding: 3px;
}

.tab {
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--hint);
    font-size: 12px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab.active {
    background: var(--bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Tab content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Loading */
.loading {
    text-align: center;
    color: var(--hint);
    padding: 40px 0;
    font-size: 14px;
}

.loading.hidden {
    display: none;
}

/* Stock table */
.stock-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--section-bg);
    border-radius: var(--radius);
    overflow: hidden;
}

.stock-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
    color: var(--hint);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--divider);
}

.stock-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--divider);
    font-size: 14px;
}

.stock-table tr:last-child td {
    border-bottom: none;
}

.stock-low {
    color: #e74c3c;
    font-weight: 700;
}

.stock-ok {
    color: #27ae60;
    font-weight: 600;
}

/* History */
.history-item {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.history-item .hi-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.history-item .hi-item {
    font-weight: 600;
    font-size: 14px;
}

.history-item .hi-qty {
    font-weight: 700;
    font-size: 14px;
}

.hi-qty.in { color: #27ae60; }
.hi-qty.out { color: #e74c3c; }

.history-item .hi-bottom {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--hint);
}

/* Period selector */
.period-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.period-btn, .top-period-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: var(--secondary-bg);
    color: var(--hint);
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn.active, .top-period-btn.active {
    background: var(--btn);
    color: var(--btn-text);
}

/* Report */
.report-summary {
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.report-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--divider);
}

.report-row:last-child {
    border-bottom: none;
}

.report-label {
    color: var(--hint);
    font-size: 13px;
}

.report-value {
    font-weight: 700;
    font-size: 14px;
}

.report-section-title {
    font-weight: 700;
    font-size: 14px;
    margin: 16px 0 8px;
    color: var(--text);
}

.report-item-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--section-bg);
    margin-bottom: 2px;
    border-radius: 8px;
    font-size: 13px;
}

/* Top */
.top-item {
    display: flex;
    align-items: center;
    background: var(--section-bg);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 6px;
}

.top-medal {
    font-size: 20px;
    width: 36px;
    text-align: center;
    flex-shrink: 0;
}

.top-num {
    width: 36px;
    text-align: center;
    color: var(--hint);
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.top-name {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
}

.top-qty {
    font-weight: 700;
    font-size: 15px;
    color: var(--link);
}

/* Empty state */
.empty {
    text-align: center;
    color: var(--hint);
    padding: 40px 0;
    font-size: 14px;
}