/* Dark theme (default) */
:root, [data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-input: #1a1a2e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --success: #00c853;
    --warning: #ffc107;
    --danger: #ff1744;
    --border: #2a2a4a;
    --sidebar-width: 220px;
    --shadow: rgba(0,0,0,0.4);
    --hover-row: rgba(255,255,255,0.02);
    --select-arrow: %23a0a0a0;
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #e8eaef;
    --bg-secondary: #f5f5f8;
    --bg-card: #ffffff;
    --bg-input: #ecedf2;
    --text-primary: #111827;
    --text-secondary: #4a5068;
    --accent: #c22845;
    --accent-hover: #d63050;
    --success: #008a38;
    --warning: #c99200;
    --danger: #c62828;
    --border: #b8bcc8;
    --shadow: rgba(0,0,0,0.15);
    --hover-row: rgba(0,0,0,0.04);
    --select-arrow: %234a5068;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    padding: 0 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.2rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(233, 69, 96, 0.1);
}

.nav-item.active {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
    border-right: 3px solid var(--accent);
}

.nav-item i { width: 20px; text-align: center; }

/* Main content */
.content {
    margin-left: var(--sidebar-width);
    padding: 2rem;
    flex: 1;
    min-height: 100vh;
    width: calc(100% - var(--sidebar-width));
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover { background: rgba(255, 23, 68, 0.1); }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover { opacity: 0.9; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
}

select.form-control {
    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='var(--select-arrow)' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    padding-right: 2.2rem;
}

/* Fix select arrow per theme since CSS vars don't work in data URIs */
[data-theme="light"] select.form-control {
    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='%234a5068' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group { flex: 1; }

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td { font-size: 0.9rem; }

tr:hover { background: var(--hover-row); }

/* Badge */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active {
    background: rgba(0, 200, 83, 0.15);
    color: var(--success);
}

.badge-muscle {
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
}

/* Grid */
.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Stats */
.stat { text-align: center; }
.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Result highlight */
.result-box {
    background: rgba(233, 69, 96, 0.1);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    margin: 1rem 0;
}

.result-box .value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
}

.result-box .label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Session time badges */
.session-am {
    background: rgba(255, 193, 7, 0.15);
    color: var(--warning);
}

.session-pm {
    background: rgba(0, 200, 83, 0.15);
    color: var(--success);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

/* Tooltips */
.tooltip {
    position: relative;
    cursor: help;
    border-bottom: 1px dotted var(--text-secondary);
}

.tooltip .tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    z-index: 500;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    box-shadow: 0 4px 16px var(--shadow);
}

.tooltip .tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--accent);
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Tooltip right-aligned variant for last columns */
.tooltip-right .tooltip-text {
    left: auto;
    right: 0;
    transform: none;
}

.tooltip-right .tooltip-text::after {
    left: auto;
    right: 1rem;
    transform: none;
}

/* Technique tag inside notes */
.technique-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: help;
    position: relative;
}

.technique-tag .tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.6rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    z-index: 500;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
    box-shadow: 0 4px 16px var(--shadow);
}

.technique-tag .tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--accent);
}

.technique-tag:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

.tag-intensity {
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent);
}

.tag-technique {
    background: rgba(0, 200, 83, 0.2);
    color: var(--success);
}

.tag-tempo {
    background: rgba(255, 193, 7, 0.2);
    color: var(--warning);
}

/* User info in sidebar */
.nav-user-info {
    padding: 0.75rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}
.nav-user-info i { width: 20px; text-align: center; font-size: 1rem; }
.nav-user-info span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Theme toggle */
.theme-toggle {
    padding: 0.75rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.theme-toggle:hover {
    color: var(--text-primary);
    background: var(--hover-row);
}

.theme-toggle i { width: 20px; text-align: center; }

/* Light theme specific overrides */
[data-theme="light"] .card {
    box-shadow: 0 2px 8px var(--shadow);
    border-color: #a8adb8;
}

[data-theme="light"] .form-control {
    border-color: #a8adb8;
}

[data-theme="light"] .form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(194, 40, 69, 0.15);
}

[data-theme="light"] .sidebar {
    border-right-color: #a8adb8;
    background: #ecedf2;
}

[data-theme="light"] .modal-overlay {
    background: rgba(0,0,0,0.4);
}

[data-theme="light"] .nav-item:hover {
    background: rgba(194, 40, 69, 0.08);
}

[data-theme="light"] .nav-item.active {
    background: rgba(194, 40, 69, 0.12);
    font-weight: 600;
}

[data-theme="light"] .badge-muscle {
    background: rgba(194, 40, 69, 0.12);
    color: #9a1e35;
}

[data-theme="light"] .badge-active {
    background: rgba(0, 138, 56, 0.12);
    color: #006a2a;
}

[data-theme="light"] .session-am {
    background: rgba(201, 146, 0, 0.15);
    color: #8a6600;
}

[data-theme="light"] .session-pm {
    background: rgba(0, 138, 56, 0.12);
    color: #006028;
}

[data-theme="light"] .tag-intensity {
    background: rgba(194, 40, 69, 0.14);
    color: #9a1e35;
}

[data-theme="light"] .tag-technique {
    background: rgba(0, 138, 56, 0.14);
    color: #006028;
}

[data-theme="light"] .tag-tempo {
    background: rgba(201, 146, 0, 0.15);
    color: #7a5800;
}

[data-theme="light"] .result-box {
    background: rgba(194, 40, 69, 0.08);
}

[data-theme="light"] .btn-secondary {
    background: var(--bg-card);
    border-color: #a8adb8;
}

[data-theme="light"] .btn-primary {
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

[data-theme="light"] table th {
    border-bottom: 2px solid #9098a8;
}

[data-theme="light"] table td {
    border-bottom: 1px solid #c0c4ce;
}

/* Utilities */
.text-muted { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Mobile header (hidden on desktop) */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3.25rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 1rem;
    z-index: 998;
    gap: 0.75rem;
}

.hamburger-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.mobile-brand {
    font-weight: 700;
    color: var(--accent);
    font-size: 1rem;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.show {
    display: block;
}

/* Responsive — Tablet & Phone (≤768px) */
@media (max-width: 768px) {
    /* Hamburger header */
    .mobile-header { display: flex; }

    /* Sidebar: off-canvas overlay */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1000;
    }
    .sidebar.open {
        transform: translateX(0);
    }

    /* Content: full width */
    .content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
        padding-top: 4rem;
    }

    /* Touch targets (Apple minimum 44px) */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 40px; }

    /* iOS zoom fix: prevent auto-zoom on input focus */
    input, select, textarea { font-size: 16px !important; }

    /* Grids */
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    /* Forms */
    .form-row { flex-direction: column; }

    /* Page header */
    .page-header { flex-direction: column; gap: 1rem; align-items: flex-start; }

    /* Tables */
    th, td { padding: 0.5rem; font-size: 0.85rem; }

    /* Modal */
    .modal { width: 95%; padding: 1.5rem; }

    /* Toast: wider on mobile */
    .toast { max-width: 100%; }
    .toast-container { left: 1rem; right: 1rem; }
}

/* Responsive — Small Phone (≤480px) */
@media (max-width: 480px) {
    .content { padding: 0.75rem; padding-top: 4rem; }
    .card { padding: 1rem; border-radius: 8px; }
    .page-header h1 { font-size: 1.2rem; }
    .stat-value { font-size: 1.4rem; }
    .grid-4 { grid-template-columns: 1fr; }
    .empty-state { padding: 2rem 1rem; }
    .empty-state i { font-size: 2rem; }
}
