/* ===== CSS Variables & Themes ===== */
:root {
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

body.dark {
    --bg: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-card-hover: #252840;
    --bg-modal: #1a1d27;
    --border: #2a2d3e;
    --text: #e8eaed;
    --text-secondary: #9aa0b0;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-bg: rgba(99, 102, 241, 0.1);
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --work-bg: rgba(34, 197, 94, 0.1);
    --work-border: rgba(34, 197, 94, 0.3);
    --off-bg: rgba(239, 68, 68, 0.05);
    --off-border: rgba(239, 68, 68, 0.2);
    --map-bg: #0d1117;
    --map-grid: #1e293b;
    --continent-fill: #1e293b;
    --continent-stroke: #334155;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --timeline-work: rgba(34, 197, 94, 0.25);
    --timeline-night: rgba(99, 102, 241, 0.15);
    --timeline-current: rgba(99, 102, 241, 0.5);
    --timeline-cell: #1e2130;
}

body.light {
    --bg: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f2f5;
    --bg-modal: #ffffff;
    --border: #e2e8f0;
    --text: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --accent: #4f46e5;
    --accent-hover: #6366f1;
    --accent-bg: rgba(79, 70, 229, 0.08);
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --work-bg: rgba(22, 163, 74, 0.06);
    --work-border: rgba(22, 163, 74, 0.25);
    --off-bg: rgba(220, 38, 38, 0.03);
    --off-border: rgba(220, 38, 38, 0.15);
    --map-bg: #eef2f7;
    --map-grid: #cbd5e1;
    --continent-fill: #c7d2de;
    --continent-stroke: #94a3b8;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --timeline-work: rgba(22, 163, 74, 0.2);
    --timeline-night: rgba(79, 70, 229, 0.1);
    --timeline-current: rgba(79, 70, 229, 0.4);
    --timeline-cell: #e2e8f0;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    overflow-x: hidden;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

input, select {
    font-family: inherit;
    font-size: inherit;
}

/* ===== Header ===== */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

#app-header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-switcher {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}

.view-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 1rem;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.view-btn.active {
    background: var(--accent);
    color: white;
}

.view-btn:hover:not(.active) {
    background: var(--bg-card-hover);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all var(--transition);
    color: var(--text-secondary);
}

.icon-btn:hover {
    background: var(--accent-bg);
    color: var(--accent);
}

.primary-btn {
    padding: 8px 20px;
    background: var(--accent);
    color: white;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition);
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* ===== Main ===== */
#app-main {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
}

.view {
    display: none;
}
.view.active {
    display: block;
}

/* ===== Clock Grid ===== */
.clocks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.clocks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.clock-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.clock-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
    opacity: 0;
    transition: opacity var(--transition);
}

.clock-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.clock-card:hover::before {
    opacity: 1;
}

.clock-card.work-time {
    border-left: 3px solid var(--success);
}

.clock-card.off-time {
    border-left: 3px solid var(--text-muted);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2px;
}

.city-name {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.city-name-en {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.remove-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: all var(--transition);
    flex-shrink: 0;
}

.remove-btn:hover {
    background: var(--danger);
    color: white;
}

.clock-time {
    font-size: 2.4rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    line-height: 1.2;
    margin-bottom: 6px;
    color: var(--text);
}

.clock-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.clock-tz {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-family: "SF Mono", "Fira Code", monospace;
}

.sun-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 6px 10px;
    background: var(--accent-bg);
    border-radius: 6px;
}

.work-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 500;
}

.work-badge.active {
    background: var(--work-bg);
    color: var(--success);
    border: 1px solid var(--work-border);
}

.work-badge:not(.active) {
    background: var(--off-bg);
    color: var(--text-muted);
    border: 1px solid var(--off-border);
}

/* ===== List view ===== */
.clocks-list .clock-card {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 16px 20px;
}

.clocks-list .card-header {
    margin-bottom: 0;
    min-width: 100px;
}

.clocks-list .city-name-en {
    margin-bottom: 0;
}

.clocks-list .clock-time {
    font-size: 1.8rem;
    margin-bottom: 0;
    min-width: 180px;
}

.clocks-list .clock-date,
.clocks-list .clock-tz,
.clocks-list .sun-info,
.clocks-list .work-badge {
    margin-bottom: 0;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state p:first-child {
    font-size: 4rem;
    margin-bottom: 16px;
}

.empty-state p:nth-child(2) {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-msg {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* ===== Map ===== */
#map-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    padding: 16px;
}

#world-map {
    width: 100%;
    height: auto;
    display: block;
}

#world-map text {
    pointer-events: none;
}

/* ===== Timeline ===== */
#timeline-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}

#timeline-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-secondary);
}

#timeline-body {
    padding: 16px;
}

.timeline-ruler {
    display: flex;
    margin-left: 100px;
    margin-bottom: 8px;
}

.timeline-hour {
    flex: 1;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    padding: 4px 0;
}

.timeline-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.timeline-city-label {
    width: 100px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
    text-align: right;
    padding-right: 12px;
}

.timeline-bar {
    flex: 1;
    display: flex;
    gap: 1px;
}

.timeline-cell {
    flex: 1;
    height: 28px;
    background: var(--timeline-cell);
    border-radius: 3px;
    transition: all var(--transition);
}

.timeline-cell.work {
    background: var(--timeline-work);
}

.timeline-cell.night {
    background: var(--timeline-night);
}

.timeline-cell.current {
    background: var(--timeline-current);
    box-shadow: 0 0 0 1px var(--accent);
}

.timeline-legend {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.timeline-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: inline-block;
}

.legend-color.work {
    background: var(--timeline-work);
}

.legend-color.current {
    background: var(--timeline-current);
}

.legend-color.night {
    background: var(--timeline-night);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-modal);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: var(--text-muted);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ===== Search ===== */
.search-box {
    margin-bottom: 12px;
}

.search-box input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition);
}

.search-box input:focus {
    border-color: var(--accent);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* ===== Continent Tabs ===== */
.continent-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.continent-tab {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: all var(--transition);
    border: 1px solid var(--border);
}

.continent-tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.continent-tab:hover:not(.active) {
    background: var(--accent-bg);
    border-color: var(--accent);
}

/* ===== City List ===== */
.city-section {
    margin-bottom: 12px;
}

.city-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}

.city-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.city-item:hover {
    background: var(--accent-bg);
}

.city-item-info {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.city-item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.city-item-en {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.add-city-btn {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    border: 1px solid var(--accent);
    transition: all var(--transition);
}

.add-city-btn:hover {
    background: var(--accent);
    color: white;
}

/* ===== Settings ===== */
.setting-group {
    margin-bottom: 20px;
}

.setting-group > label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.setting-btn {
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all var(--transition);
}

.setting-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.setting-btn:hover:not(.active) {
    border-color: var(--accent);
    color: var(--accent);
}

.setting-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

.data-actions {
    flex-direction: column;
}

.action-btn {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border: 1px solid var(--border);
    text-align: left;
    transition: all var(--transition);
    color: var(--text);
}

.action-btn:hover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.action-btn.danger:hover {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* ===== Meeting Modal ===== */
.meeting-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.meeting-success {
    padding: 12px;
    background: var(--work-bg);
    border: 1px solid var(--work-border);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    color: var(--success);
    font-weight: 600;
}

.meeting-warning {
    padding: 16px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    color: var(--warning);
}

.meeting-warning p {
    margin-bottom: 6px;
}

.meeting-slots {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.meeting-slot {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.slot-utc {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--accent);
}

.slot-cities {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.slot-city {
    font-size: 0.8rem;
    padding: 3px 10px;
    background: var(--accent-bg);
    border-radius: 20px;
    color: var(--text-secondary);
}

/* ===== Time Diff ===== */
.diff-calculator {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.diff-city-select {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.diff-city-select label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.diff-city-select select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}

.diff-city-select select:focus {
    border-color: var(--accent);
}

.diff-time {
    font-size: 1.4rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.diff-arrow {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.diff-result {
    width: 100%;
    text-align: center;
    padding: 16px;
    background: var(--accent-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.diff-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
}

.diff-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: "SF Mono", "Fira Code", monospace;
}

/* ===== Footer ===== */
#app-footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    #app-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }

    .header-right {
        flex-wrap: wrap;
        justify-content: center;
    }

    #app-main {
        padding: 16px;
    }

    .clocks-grid {
        grid-template-columns: 1fr;
    }

    .clock-time {
        font-size: 2rem;
    }

    .clocks-list .clock-card {
        flex-wrap: wrap;
        gap: 12px;
    }

    .clocks-list .clock-time {
        min-width: auto;
    }

    .modal-content {
        max-height: 90vh;
    }

    .timeline-ruler,
    .timeline-bar {
        margin-left: 0;
    }

    .timeline-city-label {
        width: 60px;
        font-size: 0.75rem;
    }

    .timeline-hour {
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    .view-switcher {
        order: -1;
        width: 100%;
        justify-content: center;
    }

    .continent-tabs {
        justify-content: center;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Selection ===== */
::selection {
    background: var(--accent);
    color: white;
}
