/* ═══════════════════════════════════════════
   Unified Calendar — Apple Calendar–Inspired
   ═══════════════════════════════════════════ */

:root {
    /* Colors — light, airy macOS palette */
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F7;
    --bg-sidebar: #F0F0F2;
    --bg-hover: #E8E8ED;
    --bg-active: #D1D1D6;
    --bg-canvas: #FFFFFF;
    --bg-today: #FFE8E8;
    --bg-selected: #E3F2FD;

    --border-light: #E5E5EA;
    --border-medium: #D1D1D6;
    --border-dark: #C7C7CC;

    --text-primary: #1D1D1F;
    --text-secondary: #6E6E73;
    --text-tertiary: #8E8E93;
    --text-inverse: #FFFFFF;

    --accent: #007AFF;
    --accent-hover: #0056CC;
    --accent-light: #E3F2FD;
    --red: #FF3B30;
    --green: #34C759;
    --orange: #FF9500;
    --purple: #AF52DE;
    --yellow: #FFCC00;
    --teal: #5AC8FA;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
    --font-size-xs: 10px;
    --font-size-sm: 11px;
    --font-size-base: 13px;
    --font-size-md: 14px;
    --font-size-lg: 17px;
    --font-size-xl: 20px;
    --font-size-xxl: 28px;

    /* Spacing */
    --toolbar-height: 52px;
    --sidebar-width: 260px;
    --inspector-width: 320px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --shadow-popover: 0 10px 40px rgba(0,0,0,0.15);

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
}

/* ═══════════════════════
   Themes (shared with Home & Health)
   ═══════════════════════ */

/* Background tone */
html[data-tweak-bg="warm"] body,
html[data-tweak-bg="warm"] #app,
html[data-tweak-bg="warm"] .toolbar,
html[data-tweak-bg="warm"] .sidebar {
    --bg-primary:   #FFFBF7;
    --bg-secondary: #FAF4EE;
    --bg-sidebar:   #F5EDE4;
    --bg-hover:     #EDE4DA;
}

html[data-tweak-bg="cool"] body,
html[data-tweak-bg="cool"] #app,
html[data-tweak-bg="cool"] .toolbar,
html[data-tweak-bg="cool"] .sidebar {
    --bg-primary:   #F7FAFF;
    --bg-secondary: #EEF4FA;
    --bg-sidebar:   #E4EDF5;
    --bg-hover:     #DAE5EF;
}

/* Density — compact mode tightens vertical rhythm */
html[data-tweak-density="compact"] .toolbar {
    height: 42px;
}
html[data-tweak-density="compact"] .event-block {
    font-size: 10px;
    padding: 1px 4px;
}
html[data-tweak-density="compact"] .sidebar-section-header {
    font-size: 10px;
    padding: 2px 8px;
}

/* ═══════════════════════
   Reset
   ═══════════════════════ */

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

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ═══════════════════════
   Toolbar
   ═══════════════════════ */

.toolbar {
    height: var(--toolbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    user-select: none;
    -webkit-app-region: drag;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    -webkit-app-region: no-drag;
}

.toolbar-center {
    flex: 1;
    text-align: center;
}

.toolbar-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.toolbar-btn:active {
    background: var(--bg-active);
}

.toolbar-btn.text-btn {
    width: auto;
    padding: 0 12px;
    font-size: var(--font-size-base);
    font-weight: 500;
    color: var(--accent);
}

.toolbar-btn.text-btn:hover {
    background: var(--accent-light);
}

.toolbar-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

.nav-arrows {
    display: flex;
    gap: 2px;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    padding: 2px;
    gap: 1px;
}

.seg-btn {
    padding: 5px 14px;
    border: none;
    background: transparent;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    white-space: nowrap;
}

.seg-btn:hover {
    color: var(--text-primary);
}

.seg-btn.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* ═══════════════════════
   Main Layout
   ═══════════════════════ */

.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ═══════════════════════
   Sidebar
   ═══════════════════════ */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    transition: margin-left 0.25s ease, opacity 0.25s ease;
}

.sidebar.hidden {
    margin-left: calc(-1 * var(--sidebar-width));
    opacity: 0;
    pointer-events: none;
}

/* Mini calendar */
.mini-calendar {
    padding: 12px 16px 8px;
}

.mini-cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.mini-cal-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-primary);
}

.mini-cal-nav {
    display: flex;
    gap: 4px;
}

.mini-cal-nav button {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.mini-cal-nav button:hover {
    background: var(--bg-hover);
}

.mini-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    text-align: center;
}

.mini-cal-dow {
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    padding: 2px 0;
    text-transform: uppercase;
}

.mini-cal-day {
    font-size: var(--font-size-sm);
    padding: 4px 0;
    cursor: pointer;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    transition: background 0.15s;
    color: var(--text-primary);
}

.mini-cal-day:hover {
    background: var(--bg-hover);
}

.mini-cal-day.other-month {
    color: var(--text-tertiary);
}

.mini-cal-day.today {
    background: var(--accent);
    color: var(--text-inverse);
    font-weight: 600;
}

.mini-cal-day.selected {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 600;
}

.mini-cal-day.today.selected {
    background: var(--accent);
    color: var(--text-inverse);
}

.mini-cal-day.has-events::after {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    margin: -2px auto 0;
}

.mini-cal-day.today.has-events::after {
    background: var(--text-inverse);
}

/* Search */
.sidebar-search {
    padding: 4px 12px 12px;
}

.sidebar-search input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.sidebar-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.1);
}

.sidebar-search input::placeholder {
    color: var(--text-tertiary);
}

/* Search results panel */
.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.search-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 12px;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    font-weight: 500;
}

.search-results-clear {
    background: none;
    border: none;
    color: var(--accent);
    font-size: var(--font-size-xs);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.search-results-clear:hover {
    background: var(--bg-hover);
}

.search-result-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    margin-bottom: 4px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
    border-left: 4px solid transparent;
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-color {
    width: 4px;
    min-height: 48px;
    border-radius: 2px;
    flex-shrink: 0;
    margin-right: 4px;
}

.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-meta {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-top: 2px;
}

.search-result-calendar {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.search-results-empty {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
}

/* Calendar list */
.calendar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.cal-group {
    margin-bottom: 8px;
}

.cal-group-header {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    user-select: none;
}

.cal-group-header:hover {
    background: var(--bg-hover);
}

.cal-group-header.drag-over {
    background: var(--accent-blue);
    color: white;
}

.cal-group-header.drag-over .cal-group-name,
.cal-group-header.drag-over .cal-group-chevron {
    color: white;
}

.cal-group-chevron {
    width: 16px;
    height: 16px;
    margin-right: 4px;
    color: var(--text-tertiary);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.cal-group.collapsed .cal-group-chevron {
    transform: rotate(-90deg);
}

.cal-group-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cal-group-items {
    padding-left: 4px;
}

.cal-group.collapsed .cal-group-items {
    display: none;
}

.cal-item {
    display: flex;
    align-items: center;
    padding: 5px 8px 5px 24px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    gap: 8px;
    transition: background 0.1s;
}

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

.cal-item-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
    position: relative;
}

.cal-item-color.checked::after {
    content: '✓';
    font-size: 9px;
    font-weight: 700;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.cal-item-color.unchecked {
    opacity: 0.3;
}

.cal-item-name {
    font-size: var(--font-size-base);
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cal-item.disabled .cal-item-name {
    color: var(--text-tertiary);
    text-decoration: line-through;
}

.cal-item-error {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
    flex-shrink: 0;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-light);
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    border-radius: var(--radius-sm);
    width: 100%;
}

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

/* ═══════════════════════
   Canvas — Main Calendar
   ═══════════════════════ */

.canvas {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-canvas);
}

/* ── Month View ── */
.month-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.month-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid var(--border-light);
}

.month-header-cell {
    padding: 8px 0;
    text-align: center;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    flex: 1;
    border-left: 1px solid var(--border-light);
}

.month-cell {
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: 4px;
    overflow: hidden;
    cursor: pointer;
    min-height: 0;
}

.month-cell:hover {
    background: var(--bg-hover);
}

.month-cell.other-month {
    background: var(--bg-secondary);
}

.month-cell.today {
    background: var(--bg-today);
}

.month-cell-date {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 2px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.month-cell.today .month-cell-date {
    background: var(--accent);
    color: var(--text-inverse);
    font-weight: 600;
}

.month-cell.other-month .month-cell-date {
    color: var(--text-tertiary);
}

.month-cell-events {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}

.event-chip {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: var(--font-size-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    line-height: 1.5;
    transition: opacity 0.1s;
}

.event-chip:hover {
    opacity: 0.85;
}

.event-chip.all-day {
    font-weight: 500;
    border-radius: 4px;
    padding: 2px 6px;
    margin: 1px 0;
    line-height: 1.4;
    white-space: normal; /* Override nowrap from .event-chip to allow wrapping */
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    min-width: 0;
    max-width: 100%;
}

.event-chip.timed {
    background: transparent !important;
    padding-left: 0;
}

.event-chip.timed .event-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 3px;
    vertical-align: middle;
}

.month-cell-more {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    padding: 1px 4px;
    cursor: pointer;
}

.month-cell-more:hover {
    color: var(--accent);
}

/* ── Week View ── */
.week-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.week-grid-scroll {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.week-sticky-top {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg-primary);
}

.week-header {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    border-bottom: 1px solid var(--border-light);
}

.week-header-gutter {
    border-right: 1px solid var(--border-light);
}

.week-header-cell {
    text-align: center;
    padding: 8px 0 4px;
    border-right: 1px solid var(--border-light);
}

.week-header-dow {
    font-size: var(--font-size-xs);
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.week-header-date {
    font-size: var(--font-size-xl);
    font-weight: 300;
    color: var(--text-primary);
    line-height: 1.3;
}

.week-header-cell.today .week-header-date {
    background: var(--accent);
    color: var(--text-inverse);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
}

/* All-day row */
.week-allday-row {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    border-bottom: 1px solid var(--border-medium);
    min-height: 28px;
}

.week-allday-label {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    padding: 4px 8px;
    border-right: 1px solid var(--border-light);
    display: flex;
    align-items: flex-start;
}

.week-allday-cell {
    border-right: 1px solid var(--border-light);
    padding: 2px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0; /* Allow grid cell to shrink below content size */
    overflow-x: hidden; /* Prevent horizontal overflow, allow vertical expansion */
}

/* Time grid */
.week-grid {
    display: grid;
    grid-template-columns: 60px repeat(7, 1fr);
    position: relative;
    min-height: calc(24 * 60px);
}

.week-time-gutter {
    position: relative;
}

.week-time-label {
    position: absolute;
    right: 8px;
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    transform: translateY(-50%);
    white-space: nowrap;
}

.week-day-column {
    border-right: 1px solid var(--border-light);
    position: relative;
}

.week-hour-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border-light);
}

.week-half-line {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed #F0F0F2;
}

.week-now-line {
    position: absolute;
    left: -4px;
    right: 0;
    height: 2px;
    background: var(--red);
    z-index: 5;
}

.week-now-line::before {
    content: '';
    position: absolute;
    left: 0;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
}

.week-event {
    position: absolute;
    left: 2px;
    right: 2px;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    font-size: var(--font-size-xs);
    overflow: hidden;
    cursor: pointer;
    border-left: 3px solid;
    z-index: 2;
    transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
}

.week-event:hover {
    opacity: 0.85;
    z-index: 10 !important;
}

.week-event-layered {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    border-left-width: 3px;
    transition: opacity 0.15s, transform 0.15s, box-shadow 0.15s;
}

.week-event-layered:hover {
    opacity: 0.95;
    transform: translateX(2px);
    z-index: 10 !important;
    box-shadow: -2px 0 8px rgba(0,0,0,0.15) !important;
}

.week-event-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.week-event-time {
    font-size: 9px;
    opacity: 0.8;
}

/* ── Day View ── */
.day-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Mobile day arrows - hidden on desktop */
.mobile-day-arrow,
.mobile-day-arrow-right-container {
    display: none;
}

.day-grid-scroll {
    flex: 1;
    overflow-y: auto;
}

.day-sticky-top {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--bg-primary);
}

.day-header {
    display: grid;
    grid-template-columns: 60px 1fr;
    border-bottom: 1px solid var(--border-light);
}

.day-header-cell {
    text-align: center;
    padding: 8px 0 4px;
}

.day-allday-row {
    display: grid;
    grid-template-columns: 60px 1fr;
    border-bottom: 1px solid var(--border-medium);
    min-height: 28px;
}

.day-grid {
    display: grid;
    grid-template-columns: 60px 1fr;
    min-height: calc(24 * 60px);
    position: relative;
}

.day-column {
    position: relative;
    border-left: 1px solid var(--border-light);
}

/* ── Year View ── */
.year-view {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    padding: 24px;
    overflow-y: auto;
    height: 100%;
}

.year-month {
    cursor: pointer;
}

.year-month-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-align: center;
}

.year-month-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    text-align: center;
}

.year-day {
    font-size: var(--font-size-xs);
    padding: 3px 0;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    color: var(--text-primary);
    cursor: pointer;
}

.year-day:hover {
    background: var(--bg-hover);
}

.year-day.other-month {
    visibility: hidden;
}

.year-day.today {
    background: var(--accent);
    color: var(--text-inverse);
    font-weight: 600;
}

.year-day.has-events {
    font-weight: 600;
    color: var(--accent);
}

.year-day.today.has-events {
    color: var(--text-inverse);
}

.year-dow {
    font-size: 9px;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    padding: 2px 0;
}

/* ═══════════════════════
   Inspector Panel
   ═══════════════════════ */

.inspector {
    width: var(--inspector-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-light);
    overflow-y: auto;
    flex-shrink: 0;
    transition: margin-right 0.25s ease, opacity 0.25s ease;
}

.inspector-content {
    padding: 20px 16px;
}

.inspector-close {
    float: right;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 0 4px;
    line-height: 1;
}

.inspector-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-bottom: 16px;
    padding-right: 28px;
    word-break: break-word;
}

.inspector-section {
    margin-bottom: 16px;
}

.inspector-label {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.inspector-value {
    font-size: var(--font-size-base);
    color: var(--text-primary);
    line-height: 1.4;
}

.inspector-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
}

.inspector-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.inspector-btn {
    padding: 7px 14px;
    border: 1px solid var(--border-medium);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-family);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.inspector-btn svg {
    flex-shrink: 0;
}

.inspector-btn:hover {
    background: var(--bg-hover);
}

.inspector-btn.primary {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}

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

.inspector-btn.danger {
    color: var(--red);
    border-color: var(--red);
}

.inspector-btn.danger:hover {
    background: #FFF0F0;
}

/* ═══════════════════════
   Modal
   ═══════════════════════ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-popover);
    width: 480px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.modal-close:hover {
    background: var(--bg-active);
}

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

.modal-footer {
    padding: 12px 20px 16px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid var(--border-light);
}

/* Unsaved Changes Warning Dialog */
.unsaved-warning-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.unsaved-warning-dialog {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popover);
    padding: 20px;
    width: 320px;
    max-width: 90vw;
}

.unsaved-warning-no {
    background: var(--yellow) !important;
    border-color: var(--yellow) !important;
    color: #000 !important;
    font-weight: 500;
}

.unsaved-warning-yes {
    background: var(--bg-hover);
    border-color: var(--border-medium);
}

/* Form elements */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.1);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.form-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* Alert/Reminder rows */
.alert-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}
.alert-row .alert-select {
    flex: 1;
}
.alert-remove {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    line-height: 1;
}
.alert-remove:hover {
    color: var(--red);
    background: rgba(255, 59, 48, 0.08);
}
.btn-add-alert {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    padding: 4px 0;
}
.btn-add-alert:hover {
    text-decoration: underline;
}

.form-color-input {
    width: 40px;
    height: 32px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
}

.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-medium);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-weight: 500;
    font-family: var(--font-family);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}

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

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

.btn-danger:hover {
    background: #FFF0F0;
}

.btn-sm {
    padding: 5px 12px;
    font-size: var(--font-size-sm);
}

/* ═══════════════════════
   Context Menu
   ═══════════════════════ */

.context-menu {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popover);
    padding: 4px;
    min-width: 180px;
    z-index: 200;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: var(--font-family);
}

.context-menu-item:hover {
    background: var(--accent);
    color: var(--text-inverse);
}

.context-menu-item.danger {
    color: var(--red);
}

.context-menu-item.danger:hover {
    background: var(--red);
    color: var(--text-inverse);
}

.context-menu-separator {
    height: 1px;
    background: var(--border-light);
    margin: 4px 8px;
}

.context-menu-submenu {
    position: relative;
}

.context-menu-submenu-trigger {
    justify-content: space-between;
}

.context-menu-submenu-items {
    display: none;
    position: absolute;
    left: 100%;
    top: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popover);
    padding: 4px;
    min-width: 140px;
    z-index: 201;
}

.context-menu-submenu:hover .context-menu-submenu-items {
    display: block;
}

/* ═══════════════════════
   Toast Notifications
   ═══════════════════════ */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--text-primary);
    color: var(--text-inverse);
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
    max-width: 320px;
}

.toast.success {
    background: var(--green);
}

.toast.error {
    background: var(--red);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════
   Empty States
   ═══════════════════════ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    gap: 12px;
    padding: 40px;
}

.empty-state-icon {
    font-size: 48px;
    opacity: 0.3;
}

.empty-state-text {
    font-size: var(--font-size-md);
    text-align: center;
}

.empty-state-action {
    margin-top: 8px;
}

/* ═══════════════════════
   Scrollbar Styling
   ═══════════════════════ */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-dark);
}

/* ═══════════════════════
   Loading indicator
   ═══════════════════════ */

.loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
    z-index: 400;
    animation: loading-slide 1.5s ease infinite;
    display: none;
}

.loading-bar.active {
    display: block;
}

@keyframes loading-slide {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(0%); }
    100% { transform: translateX(100%); }
}

/* ═══════════════════════
   Color palette for feeds
   ═══════════════════════ */

.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.selected {
    border-color: var(--text-primary);
}

/* ═══════════════════════
   Context Menu Shortcuts
   ═══════════════════════ */

.ctx-shortcut {
    margin-left: auto;
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    font-weight: 400;
}

.context-menu-item:hover .ctx-shortcut {
    color: rgba(255,255,255,0.7);
}

/* ═══════════════════════
   Settings Modal
   ═══════════════════════ */

.settings-section {
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.settings-section-title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.settings-desc {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
}

.share-url-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.share-url-input {
    font-family: 'SF Mono', SFMono-Regular, Consolas, monospace !important;
    font-size: var(--font-size-sm) !important;
}

.settings-instructions {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    line-height: 1.8;
}

.settings-instructions strong {
    color: var(--text-secondary);
}

.settings-feeds-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.settings-feed-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    font-size: var(--font-size-sm);
}

.settings-feed-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-feed-type {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    text-transform: capitalize;
}

.settings-feed-ok {
    font-size: var(--font-size-xs);
    color: var(--green);
    font-weight: 500;
}

.settings-feed-error {
    font-size: var(--font-size-xs);
    color: var(--red);
    font-weight: 500;
}

/* ═══════════════════════════════════════════
   Auth Screen — Apple-Inspired
   ═══════════════════════════════════════════ */
.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #F5F5F7 0%, #E8E8ED 50%, #F0F0F2 100%);
    z-index: 10000;
}

.auth-card {
    width: 360px;
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 36px 32px;
    text-align: center;
}

.auth-logo {
    margin-bottom: 12px;
}

.auth-title {
    font-size: var(--font-size-xxl);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    font-size: var(--font-size-md);
    color: var(--text-secondary);
    margin: 0 0 28px;
}

.auth-form .form-group {
    text-align: left;
    margin-bottom: 16px;
}

.auth-form .form-label {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}

.auth-form .form-input {
    width: 100%;
    padding: 10px 12px;
    font-size: var(--font-size-md);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.auth-form .form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.auth-error {
    background: #FFF0F0;
    color: var(--red);
    font-size: var(--font-size-sm);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    text-align: left;
}

.auth-submit {
    width: 100%;
    padding: 10px;
    font-size: var(--font-size-md);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: white;
    cursor: pointer;
    transition: background 0.15s;
}

.auth-submit:hover {
    background: var(--accent-hover);
}

.auth-switch {
    margin-top: 20px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.auth-switch-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    margin-left: 4px;
}

.auth-switch-btn:hover {
    text-decoration: underline;
}

/* ── User Avatar Button ── */
.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: 600;
    border: none;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.user-avatar:hover {
    background: var(--accent-hover);
}

/* ── Trash Badge ── */
.trash-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--red);
    color: white;
    font-size: 10px;
    font-weight: 600;
    margin-left: 4px;
}

/* ── User Menu Dropdown ── */
.user-menu {
    position: absolute;
    right: 8px;
    top: calc(var(--toolbar-height) + 4px);
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popover);
    padding: 6px 0;
    min-width: 200px;
    z-index: 5000;
}

.user-menu-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-light);
}

.user-menu-name {
    font-weight: 600;
    font-size: var(--font-size-md);
    color: var(--text-primary);
}

.user-menu-username {
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
}

.user-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 14px;
    border: none;
    background: none;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
}

.user-menu-item:hover {
    background: var(--bg-hover);
}

.user-menu-item.active {
    background: rgba(0, 122, 255, 0.10);
    color: var(--accent);
    font-weight: 600;
    position: relative;
}

.user-menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

.user-menu-item.danger {
    color: var(--red);
}

/* ── Location Autocomplete ── */
.location-autocomplete-wrap {
    position: relative;
}

.location-suggestions {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-popover);
    z-index: 1000;
    overflow: hidden;
    max-height: 220px;
    overflow-y: auto;
}

.location-suggestion-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    font-size: var(--font-size-base);
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    line-height: 1.3;
}

.location-suggestion-item:last-child {
    border-bottom: none;
}

.location-suggestion-item:hover {
    background: var(--accent-light);
}

.suggestion-icon {
    font-size: 12px;
    flex-shrink: 0;
    opacity: 0.7;
}

/* ── Location Map Preview (Inspector) ── */
.location-map-preview {
    margin-top: 8px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.location-map-iframe {
    width: 100%;
    height: 140px;
    border: none;
    display: block;
}

.location-map-link {
    display: block;
    padding: 6px 10px;
    font-size: var(--font-size-sm);
    color: var(--accent);
    text-decoration: none;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-light);
    text-align: right;
}

.location-map-link:hover {
    text-decoration: underline;
}

/* Standalone map link (no iframe) */
.inspector-section .location-map-link:only-child,
.inspector-section > .location-map-link {
    display: inline-block;
    padding: 3px 0;
    background: none;
    border: none;
    font-size: var(--font-size-sm);
}

/* ── Calendar Drag Reorder ── */
.cal-item-drag-handle {
    cursor: grab;
    opacity: 0;
    font-size: 10px;
    color: var(--text-tertiary);
    user-select: none;
    margin-right: 2px;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.cal-item:hover .cal-item-drag-handle {
    opacity: 0.6;
}

.cal-item.dragging {
    opacity: 0.4;
}

.cal-item.drag-over {
    border-top: 2px solid var(--accent);
}

/* ── Day Popover ("+N more" in Month View) ── */
.day-popover-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
}

.day-popover {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-popover);
    min-width: 280px;
    max-width: 380px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.day-popover-title {
    font-weight: 600;
    font-size: var(--font-size-md);
}

.day-popover-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.day-popover-close:hover {
    color: var(--text-primary);
}

.day-popover-events {
    padding: 8px 12px;
    overflow-y: auto;
    flex: 1;
}

.day-popover-event {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-size-base);
}

.day-popover-event:hover {
    background: var(--bg-hover);
}

.day-popover-time {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    min-width: 55px;
    flex-shrink: 0;
}

.day-popover-summary {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE STYLES
   Breakpoint: 768px (tablet portrait and below)
   ═══════════════════════════════════════════════════════════════ */

/* ── Mobile CSS Variables ── */
@media (max-width: 768px) {
    :root {
        --mobile-header-height: 56px;
        --mobile-tab-bar-height: 56px;
        --mobile-safe-top: env(safe-area-inset-top, 0px);
        --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* ── Hide Desktop Elements ── */
    .toolbar {
        display: none !important;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        margin-left: 0 !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        padding-top: var(--mobile-safe-top);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar.hidden {
        transform: translateX(-100%);
        margin-left: 0;
        opacity: 1;
        pointer-events: auto;
    }

    .inspector {
        display: none !important;
    }

    /* ── Mobile App Layout ── */
    #app {
        display: flex;
        flex-direction: column;
    }

    .main-layout {
        flex-direction: column;
        padding-top: calc(var(--mobile-header-height) + var(--mobile-safe-top));
        padding-bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom));
        height: 100%;
    }

    .canvas {
        flex: 1;
        width: 100%;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    /* ── Mobile Header ── */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-header-height) + var(--mobile-safe-top));
        padding-top: var(--mobile-safe-top);
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-light);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: 12px;
        padding-right: 12px;
        z-index: 100;
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }

    .mobile-header-left,
    .mobile-header-right {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .mobile-header-center {
        flex: 1;
        text-align: center;
        padding: 0 8px;
    }

    .mobile-header-title {
        font-size: 17px;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-header-btn {
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        color: var(--accent);
        cursor: pointer;
        border-radius: var(--radius-md);
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
        position: relative;
        z-index: 10;
    }

    .mobile-header-btn:active {
        background: var(--bg-hover);
    }

    .mobile-header-btn.text-btn {
        width: auto;
        padding: 0 10px;
        font-size: 15px;
        font-weight: 500;
    }

    /* ── Mobile Bottom Tab Bar ── */
    .mobile-tab-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom));
        padding-bottom: var(--mobile-safe-bottom);
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-light);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 100;
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
    }

    .mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 0;
        border: none;
        background: transparent;
        color: var(--text-tertiary);
        font-size: 10px;
        font-weight: 500;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s;
    }

    .mobile-tab svg {
        width: 24px;
        height: 24px;
        stroke-width: 1.5;
    }

    .mobile-tab.active {
        color: var(--accent);
    }

    .mobile-tab.active svg {
        stroke-width: 2;
    }

    /* Floating Action Button */
    .mobile-fab {
        position: fixed;
        right: 16px;
        bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom) + 16px);
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: var(--accent);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 122, 255, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 90;
        -webkit-tap-highlight-color: transparent;
        transition: transform 0.15s, box-shadow 0.15s;
    }

    .mobile-fab:active {
        transform: scale(0.95);
        box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
    }

    .mobile-fab svg {
        width: 28px;
        height: 28px;
        stroke-width: 2.5;
    }

    /* ── Drawer Overlay ── */
    .drawer-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 140;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
        -webkit-tap-highlight-color: transparent;
    }

    .drawer-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    /* ── Event Sheet (Bottom Modal) ── */
    .event-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 85vh;
        background: var(--bg-primary);
        border-radius: 16px 16px 0 0;
        z-index: 160;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .event-sheet.open {
        transform: translateY(0);
    }

    .event-sheet-handle {
        width: 36px;
        height: 5px;
        background: var(--border-medium);
        border-radius: 3px;
        margin: 10px auto;
        flex-shrink: 0;
    }

    .event-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px 12px;
        border-bottom: 1px solid var(--border-light);
    }

    .event-sheet-title {
        font-size: 17px;
        font-weight: 600;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .event-sheet-close {
        width: 32px;
        height: 32px;
        border: none;
        background: var(--bg-hover);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 18px;
        cursor: pointer;
        flex-shrink: 0;
    }

    .event-sheet-content {
        flex: 1;
        overflow-y: auto;
        padding: 16px;
        -webkit-overflow-scrolling: touch;
    }

    .event-sheet-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 155;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
    }

    .event-sheet-overlay.visible {
        opacity: 1;
        visibility: visible;
    }

    /* ── Mobile Calendar Views ── */

    /* Month View - fill available height */
    .month-view {
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .month-grid {
        flex: 1;
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        grid-template-rows: repeat(6, 1fr);
        min-height: 0;
    }

    .month-view .month-header-cell {
        font-size: 11px;
        padding: 6px 0;
    }

    .month-cell {
        padding: 2px;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .month-cell-date {
        font-size: 12px;
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    .month-cell-events {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    .event-chip {
        font-size: 9px;
        padding: 1px 3px;
    }

    .event-chip.all-day {
        padding: 1px 4px;
        font-size: 9px;
    }

    .month-cell-more {
        font-size: 9px;
    }

    /* Week View */
    .week-header {
        grid-template-columns: 44px repeat(7, 1fr);
    }

    .week-allday-row {
        grid-template-columns: 44px repeat(7, 1fr);
    }

    .week-grid {
        grid-template-columns: 44px repeat(7, 1fr);
    }

    .week-header-dow {
        font-size: 9px;
    }

    .week-header-date {
        font-size: 16px;
    }

    .week-header-cell.today .week-header-date {
        width: 26px;
        height: 26px;
    }

    .week-time-label {
        font-size: 9px;
        right: 4px;
    }

    .week-allday-label {
        font-size: 9px;
        padding: 2px 4px;
    }

    .week-event {
        font-size: 9px;
        padding: 1px 2px;
        border-left-width: 2px;
    }

    .week-event-title {
        font-size: 9px;
    }

    .week-event-time {
        display: none;
    }

    /* Mobile 2-Day Week View */
    .mobile-week-view {
        height: 100%;
    }

    .mobile-week-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 4px;
        border-bottom: 1px solid var(--border-light);
        background: var(--bg-primary);
    }

    .mobile-week-nav-btn {
        width: 36px;
        height: 36px;
        border: none;
        background: transparent;
        color: var(--accent);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border-radius: 50%;
        flex-shrink: 0;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-week-nav-btn:active {
        background: var(--bg-hover);
    }

    .mobile-week-day-header {
        flex: 1;
        text-align: center;
        padding: 4px 8px;
    }

    .mobile-week-day-header.today .mobile-week-date {
        background: var(--red);
        color: white;
        border-radius: 50%;
        width: 28px;
        height: 28px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-week-dow {
        font-size: 11px;
        font-weight: 500;
        color: var(--text-tertiary);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .mobile-week-date {
        font-size: 22px;
        font-weight: 300;
        color: var(--text-primary);
        line-height: 1.4;
    }

    .mobile-week-month {
        font-size: 10px;
        color: var(--text-tertiary);
        margin-top: -2px;
    }

    .mobile-week-allday-row {
        display: grid;
        grid-template-columns: 44px 1fr 1fr;
        border-bottom: 1px solid var(--border-medium);
        min-height: 26px;
    }

    .mobile-week-allday-gutter {
        border-right: 1px solid var(--border-light);
    }

    .mobile-week-allday-cell {
        border-right: 1px solid var(--border-light);
        padding: 2px 4px;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .mobile-week-grid {
        display: grid;
        grid-template-columns: 44px 1fr 1fr;
        position: relative;
        min-height: calc(24 * 60px);
    }

    .mobile-week-time-gutter {
        position: relative;
        border-right: 1px solid var(--border-light);
    }

    .mobile-week-day-column {
        position: relative;
        border-right: 1px solid var(--border-light);
    }

    .mobile-week-event {
        position: absolute;
        border-radius: 4px;
        padding: 4px 6px;
        font-size: 11px;
        overflow: hidden;
        border-left: 3px solid;
        z-index: 2;
        cursor: pointer;
        transition: opacity 0.1s;
    }

    .mobile-week-event:active {
        opacity: 0.8;
    }

    .mobile-week-event-layered {
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
    }

    .mobile-week-event-layered:active {
        opacity: 0.95;
    }

    .mobile-week-event-title {
        font-weight: 600;
        font-size: 12px;
        line-height: 1.3;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .mobile-week-event-time {
        font-size: 10px;
        opacity: 0.8;
        margin-top: 2px;
    }

    .mobile-week-event-location {
        font-size: 10px;
        opacity: 0.7;
        margin-top: 2px;
        display: flex;
        align-items: center;
        gap: 3px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-week-event-location svg {
        flex-shrink: 0;
    }

    /* Day View */
    .day-header {
        grid-template-columns: 44px 1fr;
    }

    .day-allday-row {
        grid-template-columns: 44px 1fr;
    }

    .day-grid {
        grid-template-columns: 44px 1fr;
    }

    /* Year View */
    .year-view {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px 12px;
        padding: 16px 12px;
        background: var(--bg-canvas);
    }

    .year-month {
        padding: 0;
    }

    .year-month-title {
        font-size: 15px;
        font-weight: 600;
        margin-bottom: 8px;
        text-align: left;
        padding-left: 2px;
    }

    .year-month.current-month .year-month-title {
        color: var(--red);
    }

    .year-month-grid {
        gap: 0;
    }

    .year-dow {
        font-size: 8px;
        padding: 2px 0;
    }

    .year-day {
        font-size: 11px;
        width: 100%;
        aspect-ratio: 1;
        padding: 0;
        height: auto;
    }

    .year-day.today {
        background: var(--red);
    }

    /* Mobile Day View Arrows */
    .mobile-day-arrow {
        display: flex;
        width: 32px;
        height: 32px;
        border: none;
        background: var(--bg-hover);
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        color: var(--accent);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-day-arrow:active {
        background: var(--bg-active);
    }

    .mobile-day-arrow-right-container {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 60px;
        border-left: none;
    }

    .day-header {
        grid-template-columns: 60px 1fr 60px !important;
        border-bottom: none;
    }

    .day-header .week-header-gutter {
        display: flex;
        align-items: center;
        justify-content: center;
        border-right: none;
    }

    .day-header-cell {
        border-left: none !important;
        border-right: none !important;
    }

    /* ── Mobile Modal Adjustments ── */
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        height: 100%;
    }

    .modal-overlay {
        align-items: stretch;
        z-index: 110; /* Above mobile header/tab bar */
    }

    .modal-body {
        padding: 16px;
    }

    /* Prevent iOS zoom on input focus */
    .form-input,
    .form-select,
    .form-textarea {
        font-size: 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* ── Day Popover on Mobile ── */
    .day-popover {
        position: fixed !important;
        left: 16px !important;
        right: 16px !important;
        top: auto !important;
        bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom) + 16px) !important;
        max-width: none;
        max-height: 50vh;
        transform: none !important;
    }

    /* ── Context Menu on Mobile ── */
    .context-menu {
        position: fixed;
        left: 16px !important;
        right: 16px !important;
        bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom) + 16px) !important;
        top: auto !important;
        min-width: auto;
    }

    /* ── Sidebar Mobile Adjustments ── */
    .sidebar {
        padding-bottom: 20px;
    }

    .sidebar-search input {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .cal-item {
        padding: 10px 8px 10px 24px;
    }

    /* ── Search Results Mobile ── */
    .search-result-item {
        padding: 12px 10px;
    }

    .search-result-title {
        font-size: 15px;
    }

    .search-result-meta {
        font-size: 13px;
    }

    .search-result-calendar {
        font-size: 12px;
    }

    /* ── Auth Screen Mobile ── */
    .auth-card {
        margin: 0 16px;
        padding: 24px 20px;
        max-width: 100%;
    }

    .auth-title {
        font-size: 22px;
    }

    /* ── Mini Calendar Mobile ── */
    .mini-cal-day {
        width: 32px;
        height: 32px;
    }

    /* ── Toast on Mobile ── */
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: calc(var(--mobile-tab-bar-height) + var(--mobile-safe-bottom) + 16px);
    }

    .toast {
        max-width: none;
    }

    /* ── Unsaved Warning Dialog Mobile ── */
    .unsaved-warning-dialog {
        width: calc(100% - 32px);
        max-width: 320px;
    }
}

/* ── Larger phones / small tablets (landscape) ── */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-header {
        height: 48px;
    }

    .main-layout {
        padding-top: 48px;
    }

    .mobile-tab-bar {
        height: 48px;
    }

    .main-layout {
        padding-bottom: 48px;
    }

    .year-view {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding: 8px;
    }

    .event-sheet {
        max-height: 90vh;
    }
}

/* ── Hide mobile elements on desktop ── */
@media (min-width: 769px) {
    .mobile-header,
    .mobile-tab-bar,
    .mobile-fab,
    .drawer-overlay,
    .event-sheet,
    .event-sheet-overlay,
    .mobile-week-view {
        display: none !important;
    }
}
