/* =========================================================
   TRACKER UI — CLEAN SYSTEM v1
   Architecture:
   1. Tokens
   2. Themes
   3. Reset
   4. Base
   5. Layout
   6. Components
   7. Overlays
   8. Animations
   9. Accessibility
========================================================= */

/* =========================================================
   1. TOKENS
========================================================= */

:root {

    /* COLORS */

    --bg-primary: #0d1020;
    --bg-secondary: #15192f;
    --bg-tertiary: #1b2140;

    --surface-1: rgba(20, 24, 42, 0.78);
    --surface-2: rgba(28, 34, 58, 0.72);
    --surface-3: rgba(36, 42, 68, 0.88);

    --border-soft: rgba(255,255,255,0.08);
    --border-medium: rgba(255,255,255,0.12);

    --text-primary: rgba(255,255,255,0.96);
    --text-secondary: rgba(255,255,255,0.68);
    --text-muted: rgba(255,255,255,0.42);

    --accent-pink: #ff4fa3;
    --accent-orange: #ff9a5f;
    --accent-cyan: #5ce1ff;
    --accent-violet: #8f7dff;

    --success-gradient:
        linear-gradient(
            135deg,
            #ff8f5a 0%,
            #ff4fa3 100%
        );
    --leave-gradient:
        linear-gradient(
            135deg,
            #8f7dff 0%,
            #5caeff 100%
        );
    --danger: #ff6b7a;

    /* RADIUS */

    --radius-sm: 14px;
    --radius-md: 20px;
    --radius-lg: 28px;
    --radius-xl: 36px;
    --radius-pill: 999px;

    /* SHADOWS */

    --shadow-sm:
        0 2px 8px rgba(0,0,0,.18);
    --shadow-md:
        0 10px 30px rgba(0,0,0,.22);
    --shadow-lg:
        0 20px 60px rgba(0,0,0,.30);
    --shadow-glow:
        0 0 20px rgba(255,79,163,.12);

    /* SPACING */

    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-7: 2rem;

    /* TYPOGRAPHY */

    --font-ui:
        "Science Gothic",
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    /* TRANSITIONS */

    --transition-fast: .12s ease;
    --transition-base: .18s ease;
    --transition-slow: .28s ease;

    /* Z */

    --z-base: 1;
    --z-header: 10;
    --z-footer: 20;
    --z-overlay: 100;
    --z-toast: 200;
}

/* =========================================================
   2. LIGHT THEME
========================================================= */

body.light-theme {

    --bg-primary: #f3f4fb;
    --bg-secondary: #ecefff;
    --bg-tertiary: #e3e7ff;

    --surface-1: rgba(255,255,255,.76);
    --surface-2: rgba(255,255,255,.88);
    --surface-3: rgba(255,255,255,.94);

    --border-soft: rgba(50,60,120,.08);
    --border-medium: rgba(50,60,120,.12);

    --text-primary: #1d2340;
    --text-secondary: rgba(29,35,64,.72);
    --text-muted: rgba(29,35,64,.42);

    --shadow-sm:
        0 2px 8px rgba(70,80,120,.06);

    --shadow-md:
        0 12px 30px rgba(70,80,120,.08);

    --shadow-lg:
        0 24px 60px rgba(70,80,120,.10);
}

/* =========================================================
   3. RESET
========================================================= */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body,
h1,
h2,
h3,
p,
button,
input,
textarea {
    margin: 0;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100vh;

    background:
        radial-gradient(
            circle at top left,
            rgba(255,79,163,.08),
            transparent 32%
        ),
        radial-gradient(
            circle at bottom right,
            rgba(92,225,255,.06),
            transparent 28%
        ),
        linear-gradient(
            180deg,
            var(--bg-secondary),
            var(--bg-primary)
        );
    color: var(--text-primary);
    font-family: var(--font-ui);
    overflow-x: hidden;
    transition:
        background var(--transition-slow),
        color var(--transition-base);
    padding:
        max(1rem, env(safe-area-inset-top))
        max(1rem, env(safe-area-inset-right))
        calc(6rem + env(safe-area-inset-bottom))
        max(1rem, env(safe-area-inset-left));
}

/* =========================================================
   4. BASE
========================================================= */

body::before {

    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(
            circle at 20% 20%,
            rgba(255,79,163,.08),
            transparent 40%
        );
    pointer-events: none;
    z-index: -1;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
}

/* =========================================================
   5. LAYOUT
========================================================= */

.app-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
    background: var(--surface-1);
    border:
        1px solid var(--border-soft);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    min-height: 82vh;
}

.header {
    position: relative;
    padding:
        max(1.5rem, env(safe-area-inset-top))
        1.5rem
        1.25rem;
    border-bottom:
        1px solid var(--border-soft);
    background:
        linear-gradient(
            180deg,
            rgba(255,255,255,.03),
            transparent
        );
}

.header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 750;
    letter-spacing: -.03em;
    margin-bottom: .4rem;
}

.header p {
    color: var(--text-secondary);
    font-size: .95rem;
}

.theme-switch-wrapper {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

/* =========================================================
   6. COMPONENTS
========================================================= */

/* ---------- BUTTONS ---------- */

.theme-toggle,
.clear-btn,
.norm-btn,
.tab-btn,
.action-menu button {
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
}

.theme-toggle {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background:
        rgba(255,255,255,.06);
    border:
        1px solid var(--border-soft);
    transition:
        transform var(--transition-fast),
        background var(--transition-base);
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1.5rem;
}

.action-btn {
    position: relative;
    min-height: 60px;
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    overflow: hidden;
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-base),
        opacity var(--transition-base);

    box-shadow: var(--shadow-md);
}

.action-btn::before {

    content: "";

    position: absolute;
    inset: 0;

    background:
        linear-gradient(
            180deg,
            rgba(255,255,255,.16),
            transparent
        );

    pointer-events: none;
}

.btn-arrive {
    background: var(--success-gradient);
}

.btn-leave {
    background: var(--leave-gradient);
}

.play-btn {
    color: var(--accent-cyan);
    font-weight: 700;
}

/* ---------- TOGGLE SWITCH ---------- */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.15);
    border-radius: 34px;
    transition: 0.2s;
    border: 1px solid var(--border-soft);
}

.slider::before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

input:checked + .slider {
    background: var(--success-gradient);
    box-shadow: 0 0 12px rgba(255,140,66,0.3);
}

input:checked + .slider::before {
    transform: translateX(24px);
}

/* ---------- LIVE TIMER ---------- */
#liveTimer {
    font-family: 'Bebas Neue', var(--font-ui);
    text-align: center;
    font-size: 2.2rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    color: var(--text-primary);
    margin: 0.5rem 0;
}

/* Подсветка кнопки Стоп при активном таймере */
.btn-leave.active-timer {
    box-shadow: 0 0 15px rgba(139,92,246,0.8);
    border: 2px solid #fff;
}

/* ---------- INPUTS ---------- */

.note-section,
.project-section {
    padding: 0 1.5rem 1.25rem;
}

.note-input,
.project-input {
    width: 100%;
    min-height: 54px;
    border-radius: var(--radius-md);
    border:
        1px solid var(--border-soft);
    background:
        rgba(255,255,255,.04);
    color: var(--text-primary);
    padding:
        .95rem 1rem;
    transition:
        border-color var(--transition-base),
        background var(--transition-base),
        box-shadow var(--transition-base);
}

.note-input::placeholder,
.project-input::placeholder {

    color: var(--text-muted);
}

.note-input:focus,
.project-input:focus {
    outline: none;
    border-color:
        rgba(92,225,255,.26);
    background:
        rgba(255,255,255,.06);
    box-shadow:
        0 0 0 4px rgba(92,225,255,.08);
}

/* ---------- STATS ---------- */

.stats-bar {

    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-top:
        1px solid var(--border-soft);
    border-bottom:
        1px solid var(--border-soft);
}

.count-badge {

    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 .9rem;
    border-radius: var(--radius-pill);
    background:
        rgba(255,255,255,.05);
    border:
        1px solid var(--border-soft);
    font-size: .85rem;
    font-weight: 600;
}

#syncIndicator {
    display: none;
    width: 8px;
    height: 8px;
    background: var(--accent-orange);
    border-radius: 50%;
    margin-right: 8px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

.today-stats {
    font-size: .85rem;
    color: var(--text-secondary);
}

.clear-btn {
    min-height: 36px;
    padding: 0 .9rem;
    border-radius: var(--radius-pill);
    background:
        rgba(255,255,255,.04);
    border:
        1px solid var(--border-soft);
    color: var(--accent-orange);
    transition:
        background var(--transition-base),
        transform var(--transition-fast);
}

.norm-btn,
#menuBtn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background var(--transition-base), transform var(--transition-fast);
}

.norm-btn:hover,
#menuBtn:hover {
    background: rgba(255,255,255,0.12);
}

/* ---------- PROGRESS BAR ---------- */
.progress-wrap {
    min-width: 80px;
}

.progress-bar {
    width: 0%;
    height: 6px;
    background: var(--accent-orange);
    border-radius: 4px;
    transition: width 0.3s ease, background 0.3s ease;
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ---------- UPDATE BAR ---------- */
#updateBar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(10px);
    color: #fff;
    padding: 10px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    font-size: 14px;
    border-bottom: 1px solid #ff8c42;
}

/* ---------- HISTORY ---------- */

.history-section {
    position: relative;
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color:
        rgba(255,255,255,.16)
        transparent;
}

#scrollTopBtn {
    display: none;
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
    z-index: 10;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
#scrollTopBtn.visible {
    display: grid;
    place-items: center;
}

.history-title {
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 700;
}

.log-container {
    display: flex;
    flex-direction: column;
    gap: .8rem;
}

#loadMoreBtn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    border-radius: 40px;
    background: rgba(255,140,66,0.15);
    border: 1px solid var(--border-soft);
    color: var(--text-primary);
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.log-item {
    padding: 1rem;
    border-radius: var(--radius-lg);
    background:
        var(--surface-2);
    border:
        1px solid var(--border-soft);
    box-shadow:
        var(--shadow-sm);
    transition:
        transform var(--transition-fast),
        border-color var(--transition-base),
        background var(--transition-base);
    animation:
        fadeIn .2s ease;
}

.log-header {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .5rem;
}

.log-type {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 .75rem;
    border-radius: var(--radius-pill);
    font-size: .75rem;
    font-weight: 700;
    background:
        rgba(255,255,255,.06);
}

.log-type.arrive {
    color: var(--accent-orange);
}

.log-type.leave {
    color: var(--accent-violet);
}

.log-type.work_start {
    color: var(--accent-orange);
}

.log-type.work_end {
    color: var(--accent-violet);
}

.log-time {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.log-date,
.log-note,
.log-project {
    color: var(--text-secondary);
    font-size: .85rem;
}

.log-note {
    margin-top: .75rem;
    padding-top: .75rem;
    border-top:
        1px solid var(--border-soft);
    line-height: 1.5;
}

.empty-state {
    padding: 4rem 1.5rem;
    text-align: center;

    color: var(--text-muted);
}

.pair-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}
.pair-time {
    font-weight: 700;
    font-size: 1rem;
}
.pair-duration {
    font-weight: 600;
    color: var(--accent-orange);
    font-size: 0.9rem;
}
.pair-actions {
    margin-top: 0.75rem;
    text-align: right;
}
.pair-continue {
    background: none;
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
}

.pair-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.5rem;
}
.pair-time {
    font-weight: 700;
    font-size: 1rem;
}
.pair-duration {
    font-weight: 600;
    color: var(--accent-orange);
    font-size: 0.9rem;
}
.pair-actions {
    margin-top: 0.75rem;
    text-align: right;
}
.pair-continue {
    background: none;
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
}
.active-duration {
    font-weight: 600;
    color: var(--accent-orange);
    white-space: nowrap;
}

.active-duration {
    font-weight: 600;
    color: var(--accent-orange);
    white-space: nowrap;
}

/* ---------- FOOTER ---------- */

.footer-bar {

    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    z-index: var(--z-footer);

    padding:
        .6rem
        1rem
        calc(.9rem + env(safe-area-inset-bottom));

    background:
        rgba(16,20,35,.78);

    border-top:
        1px solid var(--border-soft);

    backdrop-filter: blur(12px);
}

.tab-bar {

    display: flex;

    gap: .5rem;

    max-width: 620px;

    margin: 0 auto;
}

.tab-btn {

    flex: 1;

    display: flex;

    flex-direction: column;

    align-items: center;

    justify-content: center;

    min-height: 56px;

    border-radius: var(--radius-md);

    color: var(--text-secondary);

    transition:
        background var(--transition-base),
        color var(--transition-base),
        transform var(--transition-fast);
}

.tab-icon {

    font-size: 1.15rem;
    margin-bottom: .2rem;
}

.tab-label {
    color: #d2d3d9;
    font-size: .75rem;
    font-weight: 600;
}

/* =========================================================
   7. OVERLAYS
========================================================= */

.custom-modal {

    position: fixed;
    inset: 0;
    z-index: var(--z-overlay);
    display: flex;
    align-items: center;
    justify-content: center;

    background:
        rgba(0,0,0,.45);
    backdrop-filter: blur(8px);
}

.modal-content {
    width: min(92vw, 340px);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    background: var(--surface-3);
    border:
        1px solid var(--border-medium);
    box-shadow:
        var(--shadow-lg);
}

.action-menu {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 6rem;
    z-index: var(--z-overlay);
    display: flex;
    gap: .75rem;
    padding: .75rem;
    border-radius: var(--radius-lg);
    background: var(--surface-3);
    border:
        1px solid var(--border-soft);
    backdrop-filter: blur(12px);
}

.action-menu button {
    flex: 1;
    min-height: 48px;
    border-radius: var(--radius-md);
    background:
        rgba(255,255,255,.04);
}

.edit-btn {
    color: var(--accent-orange);
}

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

/* ---------- TOAST ---------- */

.custom-toast,
.undo-toast {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 6rem;
    z-index: var(--z-toast);
    min-height: 56px;
    padding: .8rem 1rem;
    border-radius: var(--radius-pill);
    background:
        rgba(15,18,30,.92);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border:
        1px solid rgba(255,255,255,.08);
    box-shadow:
        var(--shadow-md);
    animation:
        fadeUp .2s ease;
}

.undo-toast {

    justify-content: space-between;
}

.undo-toast button {
    border: none;
    min-height: 38px;
    padding: 0 1rem;
    border-radius: var(--radius-pill);
    background:
        var(--success-gradient);
    color: white;
    font-weight: 700;
}

/* ---------- SPLASH SCREEN ---------- */
#splashScreen {
    transition: opacity 0.5s ease, visibility 0.5s;
}

#splashScreen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* =========================================================
   8. ANIMATIONS
========================================================= */

@keyframes fadeIn {

    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeUp {

    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================================
   9. INTERACTION STATES
========================================================= */

@media (hover: hover) {

    .action-btn:hover {
        transform: translateY(-2px);
        box-shadow:
            var(--shadow-lg),
            var(--shadow-glow);
    }

    .log-item:hover {
        transform: translateY(-2px);
        border-color:
            rgba(255,255,255,.14);
    }

    .tab-btn:hover,
    .theme-toggle:hover,
    .clear-btn:hover,
    .action-menu button:hover {

        background:
            rgba(255,255,255,.06);
    }
}

.action-btn:active,
.tab-btn:active,
.theme-toggle:active,
.clear-btn:active,
.action-menu button:active {

    transform: scale(.98);
}

/* =========================================================
   10. REPORT DASHBOARD
========================================================= */
.report-dashboard {
    font-family: 'Science Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
}

.report-dashboard .hero {
    text-align: center;
    margin-bottom: 24px;
}

.report-dashboard .hero-label {
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: var(--accent-orange);
    font-weight: 700;
}

.report-dashboard .hero h1 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: clamp(3rem, 10vw, 4.5rem);
    font-weight: 400;
    margin: 8px 0;
    letter-spacing: 0.02em;
}

.report-dashboard .big-kpi {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 24px 0;
    flex-wrap: wrap;
}

.report-dashboard .kpi-value {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 2.8rem;
}

.report-dashboard .kpi-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.report-dashboard .chart {
    margin: 24px 0;
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
    padding: 16px;
}

.report-dashboard .bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 120px;
}

.report-dashboard .bar {
    width: 100%;
    max-width: 36px;
    background: var(--accent-orange);
    border-radius: 6px 6px 0 0;
    min-height: 4px;
}

.report-dashboard .day-card {
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.report-dashboard .insights {
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 16px;
    margin: 24px 0;
}

/* =========================================================
   11. ACCESSIBILITY
========================================================= */

:focus-visible {
    outline:
        2px solid rgba(92,225,255,.5);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {

        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}

/* =========================================================
   12. MOBILE
========================================================= */

@media (max-width: 480px) {

    .app-container {
        border-radius: 28px;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        flex-wrap: wrap;
    }

    .tab-label {
        display: none;
    }

    .tab-icon {
        margin-bottom: 0;
        font-size: 1.35rem;
    }
}

.log-item.long-press {
    transform: scale(0.97);
    box-shadow: 0 0 12px rgba(255,140,66,0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}