/* ═══════════════════════════════════════════════════════════════════════
   Программа лояльности — Mobile-first CSS
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --green: #22c55e;
    --green-dark: #16a34a;
    --red: #ef4444;
    --red-dark: #dc2626;
    --blue: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

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

/* ── Flash messages ──────────────────────────────────────────────────── */

.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    animation: slideIn 0.3s ease;
}
.flash-ok { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Header ──────────────────────────────────────────────────────────── */

header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 600px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--gray-900);
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--gray-500);
    font-size: 18px;
    text-decoration: none;
}
.btn-icon:hover { background: var(--gray-100); text-decoration: none; }

/* ── Main ────────────────────────────────────────────────────────────── */

main {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 80px;
}

/* ── Bottom nav ──────────────────────────────────────────────────────── */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px 12px;
    color: var(--gray-400);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    transition: color 0.2s;
}
.nav-item.active { color: var(--primary); }
.nav-item:hover { color: var(--primary); text-decoration: none; }
.nav-icon { font-size: 20px; margin-bottom: 2px; }

/* ── Auth pages ──────────────────────────────────────────────────────── */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: white;
    border-radius: 20px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.auth-logo {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 8px;
}

.auth-logo-img {
    max-width: 220px;
    height: auto;
    margin-bottom: 16px;
}

.auth-card h1 {
    font-size: 20px;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.auth-sub {
    color: var(--gray-500);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-card form {
    text-align: left;
}

.auth-footer {
    margin-top: 24px;
    font-size: 14px;
    color: var(--gray-500);
}

.auth-links {
    margin-top: 12px;
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 13px;
}

.ref-badge {
    background: #dbeafe;
    color: #1e40af;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
}

/* ── Inputs ──────────────────────────────────────────────────────────── */

.input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 12px;
    background: white;
    -webkit-appearance: none;
}
.input:focus { border-color: var(--primary); }
.input-sm { padding: 8px 12px; font-size: 14px; margin-bottom: 0; }

.textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.input-group .input { margin-bottom: 0; flex: 1; }

.input-suffix {
    padding: 14px 0;
    color: var(--gray-500);
    font-size: 14px;
    white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }

.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); text-decoration: none; }

.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: var(--green-dark); }

.btn-red { background: var(--red); color: white; }
.btn-red:hover { background: var(--red-dark); }

.btn-full { width: 100%; }
.btn-lg { padding: 16px 24px; font-size: 18px; }

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 8px;
}

/* ── Dashboard ───────────────────────────────────────────────────────── */

.dashboard { text-align: center; }

.balance-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 20px;
    padding: 32px 24px;
    margin-bottom: 24px;
}

.balance-label {
    font-size: 14px;
    opacity: 0.8;
    margin-bottom: 8px;
}

.balance-value {
    font-size: 42px;
    font-weight: 800;
    line-height: 1.1;
}
.balance-value small { font-size: 18px; font-weight: 500; opacity: 0.8; }

.balance-sub {
    margin-top: 12px;
    font-size: 13px;
    opacity: 0.7;
}

.qr-section {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}
.qr-section h2 { font-size: 18px; margin-bottom: 4px; }
.qr-section p { font-size: 13px; color: var(--gray-500); margin-bottom: 16px; }
.qr-img { width: 200px; height: 200px; border-radius: 8px; }
.qr-id { margin-top: 8px; font-size: 13px; color: var(--gray-400); }

/* ── Page ────────────────────────────────────────────────────────────── */

.page h1 { font-size: 22px; margin-bottom: 16px; }
.page h2 { font-size: 18px; margin-bottom: 12px; margin-top: 24px; }

.back-link {
    display: inline-block;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--gray-500);
}

.text-muted { color: var(--gray-500); font-size: 13px; }

.divider {
    text-align: center;
    margin: 20px 0;
    color: var(--gray-400);
    position: relative;
}
.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--gray-200);
}
.divider::before { left: 0; }
.divider::after { right: 0; }
.divider span { padding: 0 12px; background: var(--gray-50); font-size: 13px; }

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--gray-500);
}

/* ── Transactions ────────────────────────────────────────────────────── */

.tx-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
}

.tx-left { flex: 1; }
.tx-right { text-align: right; }
.tx-name { font-weight: 600; font-size: 14px; }
.tx-type { font-size: 13px; font-weight: 500; }
.tx-store { font-size: 12px; color: var(--gray-400); }
.tx-date { font-size: 12px; color: var(--gray-400); }
.tx-amount { font-size: 16px; font-weight: 700; }
.tx-purchase { font-size: 12px; color: var(--gray-400); }

.tx-green { color: var(--green); }
.tx-red { color: var(--red); }
.tx-blue { color: var(--blue); }
.tx-gray { color: var(--gray-500); }

/* ── Referrals ───────────────────────────────────────────────────────── */

.ref-link-section { margin: 16px 0; }
.ref-link-section label { font-size: 14px; color: var(--gray-500); display: block; margin-bottom: 6px; }
.ref-link-box { display: flex; gap: 8px; }
.ref-link-box .input { margin-bottom: 0; font-size: 13px; }

.ref-list, .ref-item { margin-bottom: 8px; }
.ref-item {
    background: white;
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
}
.ref-name { font-weight: 600; font-size: 15px; }
.ref-info { font-size: 13px; color: var(--gray-500); }

/* ── Rules ────────────────────────────────────────────────────────────── */

.rules-list { display: flex; flex-direction: column; gap: 12px; }
.rule-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}
.rule-card h3 { font-size: 16px; margin-bottom: 8px; color: var(--primary); }
.rule-card p { font-size: 14px; color: var(--gray-600); margin-bottom: 4px; }

/* ── Info card ────────────────────────────────────────────────────────── */

.info-card {
    background: #ede9fe;
    color: #5b21b6;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    font-size: 14px;
}

/* ── Cashier ─────────────────────────────────────────────────────────── */

.cashier-header { margin-bottom: 16px; }
.cashier-info { font-size: 14px; color: var(--gray-500); }

.cashier-actions { margin-bottom: 24px; }

.qr-reader {
    border-radius: var(--radius);
    overflow: hidden;
    margin: 16px 0;
}

.search-form { margin-top: 0; }

.search-results { margin-top: 16px; }
.result-card {
    display: block;
    background: white;
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    margin-bottom: 8px;
    text-decoration: none;
    color: inherit;
}
.result-card:hover { box-shadow: var(--shadow-lg); text-decoration: none; }
.result-name { font-weight: 600; }
.result-info { font-size: 13px; color: var(--gray-500); }

.client-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    text-align: center;
    margin-bottom: 24px;
}
.client-card h1 { margin-bottom: 4px; }
.client-phone { color: var(--gray-500); font-size: 15px; margin-bottom: 16px; }
.client-balance { margin-bottom: 8px; }
.balance-big { font-size: 36px; font-weight: 800; color: var(--primary); }
.balance-label { font-size: 14px; color: var(--gray-500); }
.client-stats { font-size: 13px; color: var(--gray-500); }
.client-meta { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

.cashier-forms, .admin-forms {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-section {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.form-section h2 { font-size: 16px; margin-bottom: 8px; margin-top: 0; }

/* ── Cashier select ──────────────────────────────────────────────────── */

.cashier-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.cashier-select-form { width: 100%; }
.cashier-select-btn {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}
.cashier-select-btn:hover { border-color: var(--primary); background: var(--gray-50); }
.cashier-select-btn .cashier-name { font-weight: 600; font-size: 16px; }
.cashier-select-btn .cashier-store { font-size: 13px; color: var(--gray-500); }

/* ── Admin ───────────────────────────────────────────────────────────── */

.admin-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 24px;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-weight: 600;
    font-size: 14px;
    color: var(--gray-700);
    text-decoration: none;
    transition: all 0.2s;
}
.admin-nav-item:hover { box-shadow: var(--shadow-lg); color: var(--primary); text-decoration: none; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-card.stat-wide { grid-column: span 2; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--gray-900); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 2px; }

.stats-section { margin-bottom: 24px; }
.stats-section h2 { font-size: 18px; margin-bottom: 12px; margin-top: 0; }

/* ── Tables ──────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: var(--radius); }

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 14px;
}
.data-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    font-size: 12px;
    text-transform: uppercase;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
}

/* ── Settings ────────────────────────────────────────────────────────── */

.setting-row {
    margin-bottom: 16px;
}
.setting-row label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

/* ── Stores ───────────────────────────────────────────────────────────── */

.stores-list, .cashiers-list, .users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.store-card, .cashier-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.store-info, .cashier-info { flex: 1; }
.store-name { font-weight: 600; font-size: 15px; }
.store-addr { font-size: 13px; color: var(--gray-500); }
.store-cashiers { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

.cashier-card { flex-direction: column; align-items: stretch; }
.cashier-actions-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}
.cashier-actions-row .inline-form { display: flex; gap: 4px; flex: 1; }
.cashier-actions-row select { flex: 1; }

.user-card {
    display: block;
    background: white;
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
}
.user-card:hover { box-shadow: var(--shadow-lg); text-decoration: none; }
.user-name { font-weight: 600; }
.user-info { font-size: 13px; color: var(--gray-500); }

/* ── Announcements ───────────────────────────────────────────────────── */

.announcements { text-align: left; margin-top: 16px; }
.announcements h3 { font-size: 16px; margin-bottom: 12px; }

.announcement-item, .announcement-card {
    background: white;
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    margin-bottom: 8px;
}
.announcement-text { font-size: 14px; white-space: pre-line; }
.announcement-date { font-size: 12px; color: var(--gray-400); margin-top: 4px; }

.announcement-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
}

.announcements-admin { margin-top: 24px; }

/* ── Select ──────────────────────────────────────────────────────────── */

select.input {
    -webkit-appearance: none;
    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='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── Responsive ──────────────────────────────────────────────────────── */

@media (min-width: 768px) {
    .auth-card { padding: 40px 32px; }
    .admin-nav { grid-template-columns: repeat(3, 1fr); }
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
