/* ======================================================
   Часове & Бонуси — Mobile-first PWA
   ====================================================== */

:root {
    color-scheme: light dark;
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-dark: #cbd5e1;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
    --radius: 12px;
    --radius-lg: 16px;
    --header-h: 64px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

input, textarea, select {
    user-select: text;
    font-family: inherit;
    font-size: 16px; /* prevents iOS zoom */
}

h1, h2, h3 {
    margin: 0;
    font-weight: 700;
    color: var(--text);
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

p { margin: 0; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

.demo-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: rgba(245,158,11,.15);
    color: var(--warning);
    border: 1px solid rgba(245,158,11,.35);
    border-radius: 10px;
    font-size: .9rem;
    font-weight: 500;
}
.demo-banner .btn {
    flex: 0 0 auto;
    background: var(--warning);
    color: #fff;
    border: none;
}

/* ============ SCREENS ============ */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;
}
.screen.active { display: flex; }

.container {
    padding: env(safe-area-inset-top) 20px 20px;
    padding-top: calc(env(safe-area-inset-top) + 20px);
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* ============ SPLASH ============ */
#splash {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    align-items: center;
    justify-content: center;
}
.splash-inner { text-align: center; }
.splash-logo { font-size: 4rem; margin-bottom: 16px; }
#splash h1 { color: white; margin-bottom: 32px; }
#splash-msg { opacity: .8; margin-top: 16px; }
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ HERO ============ */
.hero {
    text-align: center;
    padding: 12px 0 16px;
}
.hero-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}
.hero h1 {
    font-size: 1.75rem;
    margin-bottom: 4px;
}
.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ============ CARDS ============ */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.card h2 { margin-bottom: 8px; }
.card h3 { margin-bottom: 8px; }
.card p { margin-bottom: 16px; }
.card p:last-child { margin-bottom: 0; }

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .1s, box-shadow .2s, background .2s;
    text-decoration: none;
    -webkit-appearance: none;
    min-height: 44px;
}
.btn:active { transform: scale(.97); }
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-dark);
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-success {
    background: var(--success);
    color: white;
}
.btn-lg { padding: 16px 24px; font-size: 1.1rem; min-height: 52px; }
.btn-sm { padding: 8px 14px; font-size: .9rem; min-height: 36px; }
.btn-full { width: 100%; margin: 16px 0; }

.icon-btn {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}
.icon-btn:hover { background: rgba(0,0,0,.05); }

/* ============ PIN LOGIN ============ */
.pin-display {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin: 12px 0 12px;
}
.pin-display-6 {
    gap: 12px;
}
.pin-display-6 .pin-dot {
    width: 16px;
    height: 16px;
}
.pin-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border-dark);
    background: transparent;
    transition: all .2s;
}
.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.1);
}
.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-width: 320px;
    margin: 12px auto 0;
}
.key {
    aspect-ratio: 1;
    border: none;
    background: var(--surface);
    border-radius: 50%;
    font-size: 1.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform .1s, background .15s;
    box-shadow: var(--shadow-sm);
    color: var(--text);
}
.key:active,
.key.pressed {
    transform: scale(.92);
    background: var(--primary-light);
    color: #fff;
    box-shadow: 0 0 0 6px rgba(59, 130, 246, .22), var(--shadow-sm);
}
.key-action { font-size: 1.3rem; color: var(--text-muted); background: transparent; box-shadow: none; }
.key-action:active,
.key-action.pressed {
    background: rgba(59, 130, 246, .15);
    color: var(--primary);
    box-shadow: none;
}

.error-msg {
    text-align: center;
    color: var(--danger);
    background: rgba(239,68,68,.1);
    padding: 8px;
    border-radius: 8px;
    margin: 0 auto;
    max-width: 320px;
    animation: shake .4s;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* ============ APP HEADER ============ */
.app-header {
    padding: env(safe-area-inset-top) 16px 0;
    padding-top: calc(env(safe-area-inset-top) + 12px);
    padding-bottom: 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 10;
}
.admin-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}
.admin-header .user-name, .admin-header .user-sub { color: white; }
.admin-header .icon-btn { color: white; }

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.admin-avatar { background: var(--accent); }
.user-name { font-weight: 600; font-size: 1rem; }
.user-sub { font-size: .8rem; color: var(--text-muted); }

.content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}

/* ============ STATS ============ */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.stat-card.highlight {
    background: linear-gradient(135deg, var(--accent) 0%, #d97706 100%);
    color: white;
    border: none;
    cursor: pointer;
    transition: transform .1s;
}
.stat-card.highlight:active { transform: scale(0.97); }
.stat-label { font-size: .75rem; opacity: .85; margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 1.5rem; font-weight: 700; }

.bonus-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}
.bonus-summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
}
.bonus-summary-pending {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.bonus-summary-label {
    font-size: .75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}
.bonus-summary-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

/* ============ TABS ============ */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow-x: auto;
}
.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
    transition: all .2s;
    white-space: nowrap;
}
.tab.active {
    background: var(--primary);
    color: white;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.sub-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}
.sub-tab {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 20px;
    font-size: .85rem;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
}
.sub-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 10px;
    flex-wrap: wrap;
}
.section-header h2 { font-size: 1.1rem; }

.select-sm {
    padding: 6px 10px;
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    background: var(--surface);
    font-size: .85rem;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
    font-size: .85rem;
    color: var(--text-muted);
    font-weight: 500;
}
.filter-row label,
label.filter-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    flex: 1 1 220px;
}
.filter-row select,
.filter-row input[type="date"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-dark);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: .95rem;
}

/* ============ LISTS ============ */
.list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.list-item {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform .15s;
}
.list-item:active { transform: scale(.98); }
.list-item-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}
.list-item-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.list-item-sub {
    font-size: .85rem;
    color: var(--text-muted);
}
.list-item-badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-success { background: rgba(16,185,129,.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: #fff; }
.badge-muted { background: var(--bg); color: var(--text-muted); }
.badge-danger { background: rgba(239,68,68,.15); color: var(--danger); }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 3rem;
    opacity: .4;
    margin-bottom: 12px;
}

/* ============ MODAL ============ */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 100;
    align-items: flex-end;
    justify-content: center;
}
.modal.active { display: flex; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.4);
    animation: fadeIn .2s;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.modal-sheet {
    position: relative;
    background: var(--surface);
    width: 100%;
    max-width: 520px;
    border-radius: 24px 24px 0 0;
    padding: 20px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp .3s cubic-bezier(.32,.72,0,1);
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* ============ FORMS ============ */
.form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text);
}
.form input[type="text"],
.form input[type="number"],
.form input[type="date"],
.form input[type="password"],
.form textarea,
.form select {
    padding: 12px;
    border: 1.5px solid var(--border-dark);
    border-radius: 10px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s;
    width: 100%;
    -webkit-appearance: none;
}
.form input:focus, .form textarea:focus, .form select:focus {
    outline: none;
    border-color: var(--primary);
}
.form textarea { resize: vertical; min-height: 60px; }
.form small { font-size: .75rem; color: var(--text-muted); font-weight: normal; }

.checkbox-label {
    flex-direction: row !important;
    align-items: center;
    gap: 10px !important;
    font-weight: normal !important;
}
.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.form-actions .btn { flex: 1; min-width: 100px; }
#btn-delete-worker { flex: 0; margin-right: auto; min-width: auto; }

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 24px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: .95rem;
    font-weight: 500;
    z-index: 200;
    opacity: 0;
    transition: all .3s;
    max-width: 90%;
    box-shadow: var(--shadow-lg);
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error { background: var(--danger); }

/* ============ PUSH PROMPT ============ */
.push-prompt {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    left: 12px;
    right: 12px;
    z-index: 90;
    animation: slideUpSmall .3s;
}
@keyframes slideUpSmall {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.push-prompt-inner {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 14px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.push-prompt .push-icon { font-size: 1.5rem; }
.push-text { display: flex; flex-direction: column; gap: 2px; }
.push-text small { font-size: .8rem; color: var(--text-muted); }
.push-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ============ UTILITIES ============ */
@media (min-width: 600px) {
    .container { max-width: 560px; margin: 0 auto; }
    .content { max-width: 720px; margin: 0 auto; width: 100%; }
    .stats-row { grid-template-columns: repeat(3, 1fr); }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --surface: #1e293b;
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --border: #334155;
        --border-dark: #475569;
    }
    .key { background: #334155; }
    .key:active { background: #475569; }
    .key-action { background: transparent; }
    .list-item, .card, .stat-card, .app-header { background: var(--surface); }
}
