/* Base Styles & Tokens */
:root {
    --primary: #8B5CF6;
    --primary-hover: #7C3AED;
    --primary-glow: rgba(139, 92, 246, 0.4);

    --bg-base: #020617;
    /* Slate 950 */
    --bg-surface: #0F172A;
    /* Slate 900 */
    --bg-glass: rgba(15, 23, 42, 0.6);
    --bg-glass-hover: rgba(15, 23, 42, 0.8);

    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(139, 92, 246, 0.2);

    --text-main: #F8FAFC;
    --text-sec: #94A3B8;

    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;

    /* Timezone Status Colors */
    --tz-work: rgba(16, 185, 129, 0.2);
    /* Green tint */
    --tz-sleep: rgba(244, 63, 94, 0.2);
    /* Rose tint */
    --tz-shoulder: rgba(245, 158, 11, 0.2);
    /* Amber tint */

    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 6px;

    --font: 'Outfit', sans-serif;

    --grid-cell-width: 40px;
}

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

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.1) 0%, transparent 50%);
    background-attachment: fixed;
}

.app-container {
    width: 100%;
    max-width: 1400px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Header */
header {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.actions {
    display: flex;
    gap: 12px;
}

.meeting-details {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.flex-1 {
    flex: 1;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 0.85rem;
    color: var(--text-sec);
    font-weight: 500;
}

input,
select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    border: none;
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary-btn {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.primary-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.secondary-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn {
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid transparent;
}

.icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

/* Workspace Layout */
.workspace {
    display: flex;
    gap: 24px;
    flex: 1;
    overflow: hidden;
    /* Prevent body scroll, handle scroll inside component */
}

/* Sidebar */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
}

.participant-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 4px;
}

.participant-list::-webkit-scrollbar {
    width: 6px;
}

.participant-list::-webkit-scrollbar-track {
    background: transparent;
}

.participant-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.participant-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.participant-info {
    display: flex;
    flex-direction: column;
}

.p-name {
    font-weight: 500;
    font-size: 1rem;
}

.p-tz {
    font-size: 0.8rem;
    color: var(--text-sec);
    display: flex;
    align-items: center;
    gap: 4px;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--text-sec);
    cursor: pointer;
    transition: color 0.2s;
}

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

.add-participant-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.search-container {
    position: relative;
}

.suggestions {
    position: absolute;
    bottom: 100%;
    /* pop up instead of down */
    left: 0;
    right: 0;
    margin-bottom: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    max-height: 200px;
    overflow-y: auto;
    list-style: none;
    z-index: 10;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
}

.suggestions.hidden {
    display: none;
}

.suggestions li {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.suggestions li:last-child {
    border: none;
}

.suggestions li:hover {
    background: rgba(255, 255, 255, 0.05);
}

.presets label {
    font-size: 0.8rem;
    color: var(--text-sec);
    display: block;
    margin-bottom: 8px;
}

.preset-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.preset-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 20px;
    color: var(--text-sec);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Timeline View */
.timeline-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    padding: 0;
}

.timeline-controls {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
}

.timeline-controls h3 {
    font-weight: 500;
    font-size: 1.1rem;
    min-width: 150px;
    text-align: center;
}

.spacer {
    flex: 1;
}

.legend {
    display: flex;
    gap: 16px;
    font-size: 0.85rem;
    color: var(--text-sec);
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

.dot.work {
    background: var(--success);
}

.dot.sleep {
    background: var(--danger);
    opacity: 0.6;
}

/* Grid specific */
.grid-wrapper {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    position: relative;
    padding: 20px 24px;
    /* Hide scrollbar for grid but allow scrolling */
}

.grid-wrapper::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.grid-wrapper::-webkit-scrollbar-track {
    background: var(--bg-surface);
}

.grid-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}


.hour-headers {
    display: flex;
    position: relative;
    margin-bottom: 12px;
    margin-left: 120px;
    /* Offset for names */
    min-width: max-content;
}

.hour-label {
    width: var(--grid-cell-width);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-sec);
    flex-shrink: 0;
}

.timeline-rows {
    position: relative;
    min-width: max-content;
}

.tz-row {
    display: flex;
    margin-bottom: 8px;
    align-items: stretch;
}

.tz-label {
    width: 120px;
    flex-shrink: 0;
    padding-right: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-sec);
    text-align: right;
    border-right: 1px solid var(--border-color);
    margin-right: -1px;
    /* Overlap border */
    z-index: 2;
    background: var(--bg-base);
    /* keep solid if sticky, but simplified here */
}

/* Base cell styling */
.tz-cell {
    width: var(--grid-cell-width);
    height: 36px;
    flex-shrink: 0;
    border: 1px dashed rgba(255, 255, 255, 0.05);
    border-left: none;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    user-select: none;
}

.tz-cell.tz-night {
    background-color: var(--tz-sleep);
    color: rgba(255, 255, 255, 0.4);
}

.tz-cell.tz-work {
    background-color: var(--tz-work);
    color: var(--text-main);
    font-weight: bold;
}

.tz-cell.tz-shoulder {
    background-color: var(--tz-shoulder);
    color: var(--text-main);
}

.tz-cell.tz-day-change {
    border-left: 2px solid var(--primary);
}

/* Selection overlay overlayed over the cells */
.selection-layer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 120px;
    /* Offset for labels */
    right: 0;
    pointer-events: none;
    /* Let clicks pass through to a transparent trigger area */
    z-index: 5;
}

.selection-box {
    position: absolute;
    top: -10px;
    bottom: -10px;
    background: rgba(139, 92, 246, 0.2);
    border: 2px solid var(--primary);
    border-radius: 4px;
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
    pointer-events: none;
    transition: left 0.1s, width 0.1s;
}

/* Invisible overlay to catch drag events cleanly */
.interaction-layer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 120px;
    width: calc(100% - 120px);
    z-index: 10;
    cursor: col-resize;
}

/* Result Bar */
.result-bar {
    border-top: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    background: rgba(0, 0, 0, 0.2);
}

.selected-time-summary h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary);
}

.text-muted {
    color: var(--text-sec);
    font-size: 0.9rem;
}

.selection-details {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.selection-details li {
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
}

.selection-details li span.time {
    font-family: monospace;
    font-size: 0.95rem;
    font-weight: bold;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    font-weight: 500;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
    pointer-events: none;
}

/* Utilities */
.mt-4 {
    margin-top: 16px;
}

/* Responsive tweaks */
@media (max-width: 1024px) {
    .app-container {
        padding: 12px;
    }

    .workspace {
        flex-direction: column;
        overflow: auto;
    }

    .sidebar {
        width: 100%;
        max-height: 400px;
    }

    .timeline-container {
        height: 600px;
        flex: none;
    }
}