/* Responsive layer, deliberately after the original desktop styles. */
:root { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
button, input, select, textarea { font: inherit; }
button, [role="button"] { touch-action: manipulation; }
:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
.main-view { min-width: 0; }
.local-mode-status { margin: 0 0 18px; color: var(--text-muted); font-size: .8rem; line-height: 1.5; }
.notes-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.notes-toolbar input { flex: 1; min-width: 0; margin: 0; }
#notesCount { flex-shrink: 0; font-size: .8rem; color: var(--text-muted); }
.note-open { display: flex; flex: 1; flex-direction: column; gap: 12px; width: 100%; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; color: #334155; cursor: pointer; }
.note-preview-title, .note-preview { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.note-preview-title { -webkit-line-clamp: 2; font-size: 1.05rem; line-height: 1.4; padding-right: 24px; }
.note-preview { -webkit-line-clamp: 4; white-space: pre-wrap; font-size: .9rem; line-height: 1.5; }
.note-preview-footer { display: flex; justify-content: space-between; gap: 12px; margin-top: auto; padding-top: 8px; font-size: .72rem; color: #475569; width: 100%; }
.post-it:focus-within .delete-btn { opacity: 1; }
.notes-empty { grid-column: 1 / -1; padding: 24px 8px; text-align: center; color: var(--text-muted); line-height: 1.5; }
.modal { max-height: calc(100dvh - 40px); overflow-y: auto; }
.schedule-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.schedule-fields label { display: block; margin-bottom: 6px; font-size: .85rem; font-weight: 600; }
.mobile-header, .mobile-nav, .mobile-quick-actions, .sidebar-backdrop { display: none; }
.sidebar-toggle { display: grid; place-items: center; width: 44px; height: 44px; flex-shrink: 0; margin-bottom: 8px; padding: 10px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--white); color: var(--text-muted); cursor: pointer; }
.sidebar-toggle svg { width: 22px; height: 22px; }
.sidebar-toggle[aria-expanded="true"] { color: var(--primary-blue); background: #eff6ff; }
body.sidebar-collapsed .side-panel { display: none; }
.sidebar-drawer-heading { display: none; }
.app-notice { position: fixed; z-index: 10000; bottom: 24px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); padding: 14px 20px; background: #163c32; color: white; border-radius: 14px; box-shadow: 0 8px 30px #0002; font-size: .9rem; }
.app-notice.is-error { background: #7c2d12; }
.app-notice[hidden], .sidebar-backdrop[hidden] { display: none !important; }
.view-btn.active { background: var(--white) !important; color: var(--primary-blue) !important; box-shadow: 0 1px 4px #0002 !important; }
.view-btn:not(.active) { background: transparent !important; color: var(--text-muted) !important; box-shadow: none !important; }
.mobile-menu { border: 0; border-radius: 24px; padding: 24px; margin: auto; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); color: var(--text-main); background: var(--white); }
.mobile-menu::backdrop { background: #0f172a99; backdrop-filter: blur(4px); }
.mobile-menu-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.mobile-menu-heading small { color: var(--text-muted); font-size: .65rem; letter-spacing: .12em; }
.mobile-menu-heading h2 { margin-top: 8px; font-size: 1.3rem; }
.mobile-menu-heading button { min-width: 44px; min-height: 44px; background: var(--hover-bg); border: 0; border-radius: 50%; font-size: 1.6rem; color: inherit; }
.mobile-menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mobile-menu-grid button { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; padding: 16px; border: 1px solid var(--border-color); border-radius: 16px; text-align: left; background: var(--bg-color); color: var(--text-main); cursor: pointer; }
.mobile-menu-grid svg { width: 24px; height: 24px; color: var(--primary-blue); margin-bottom: 3px; }
.mobile-menu-grid span { color: var(--text-muted); font-size: .73rem; line-height: 1.4; }
.mobile-menu-grid .active { border-color: var(--primary-blue); background: #2563eb0b; }
.menu-settings { margin-top: 16px; padding: 14px; width: 100%; border: 1px solid var(--border-color); border-radius: 12px; background: var(--white); color: var(--text-main); }
@media (min-width: 761px) and (max-width: 1100px) {
    .side-panel { display: none; }
    .side-panel.is-open { display: flex; position: fixed; inset: 0 auto 0 64px; width: min(300px, calc(100vw - 64px)); padding: 18px; z-index: 80; background: var(--white); box-shadow: 8px 0 28px #0002; }
    .sidebar-drawer-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
    .sidebar-drawer-heading button { width: 44px; height: 44px; border: 0; background: var(--hover-bg); color: var(--text-main); border-radius: 12px; font-size: 1.4rem; }
    .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0 0 0 64px; width: calc(100% - 64px); height: 100%; border: 0; background: #0f172a66; z-index: 70; }
    .nav-rail { width: 64px; }
    .dashboard-columns { grid-template-columns: 1fr !important; }
    .top-bar { padding: 18px; }
}
@media (max-width: 760px), (pointer: coarse) and (max-width: 1100px) and (max-height: 500px) {
    body { display: block; height: 100dvh; overflow: hidden; padding-top: calc(74px + env(safe-area-inset-top)); padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
    .nav-rail { display: none; }
    .side-panel { display: none; }
    .sidebar-drawer-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
    .sidebar-drawer-heading button { width: 44px; height: 44px; border: 0; background: var(--hover-bg); color: var(--text-main); border-radius: 12px; font-size: 1.4rem; }
    .mobile-header { display: flex; align-items: center; gap: 12px; position: fixed; inset: 0 0 auto; height: calc(74px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 18px 0; z-index: 60; background: var(--white); border-bottom: 1px solid var(--border-color); }
    .mobile-brand { display: flex; align-items: center; gap: 11px; flex: 1; }
    .mobile-monogram { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: var(--primary-blue); color: white; font-weight: 800; box-shadow: 0 5px 12px #2563eb25; }
    .mobile-brand small { display: block; font-size: .58rem; font-weight: 700; letter-spacing: .15em; color: var(--text-muted); margin-bottom: 4px; }
    .mobile-brand strong { display: block; font-size: 1.05rem; }
    .mobile-filter, .mobile-profile { display: grid; place-items: center; min-width: 44px; min-height: 44px; border: 1px solid var(--border-color); border-radius: 14px; background: var(--white); color: var(--text-main); }
    .mobile-filter svg { width: 21px; height: 21px; }
    .mobile-profile { border-radius: 50%; background: #eef2ff; color: #3730a3; font-weight: 700; font-size: .8rem; }
    .mobile-nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; position: fixed; inset: auto 0 0; height: calc(76px + env(safe-area-inset-bottom)); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--white); border-top: 1px solid var(--border-color); z-index: 60; box-shadow: 0 -4px 24px #0f172a05; }
    .mobile-nav button { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 5px; min-height: 52px; min-width: 0; border: 0; border-radius: 12px; color: var(--text-muted); background: none; font-size: .65rem; font-weight: 600; }
    .mobile-nav svg { width: 22px; height: 22px; }
    .mobile-nav .active { color: var(--primary-blue); background: #2563eb0b; }
    .mobile-nav .mobile-create { background: var(--primary-blue); color: white; margin: 0 6px; box-shadow: 0 4px 12px #2563eb25; }
    .main-view { width: 100%; height: 100%; overflow: auto; padding: 18px !important; position: relative; }
    #view-calendar { padding: 0 !important; overflow: hidden; min-height: 0; }
    .top-bar { padding: 18px !important; flex-shrink: 0; flex-wrap: wrap; height: auto; gap: 12px !important; }
    .top-bar h1, .top-bar h2 { font-size: 1.35rem !important; }
    .view-title { width: 100%; flex-wrap: wrap; gap: 8px; }
    #view-calendar .top-bar { padding: 8px 12px !important; gap: 8px !important; margin-bottom: 0; }
    #view-calendar .view-title { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; }
    #currentDateLabel { flex: 1; min-width: 0 !important; width: auto; font-size: .95rem !important; margin: 0; line-height: 1.3; }
    #view-calendar .nav-arrows { flex-shrink: 0; gap: 2px; }
    #view-calendar .nav-arrow { width: 32px; min-width: 32px; padding: 0; font-size: .8rem; }
    #view-calendar .btn-today { margin: 0; padding: 0 10px; font-size: .8rem; }
    #view-calendar .calendar-actions { display: none !important; }
    .view-switcher { width: 100%; margin-right: 0 !important; }
    .view-switcher .view-btn { flex: 1; padding: 6px 2px !important; font-size: .75rem !important; min-width: 0; }
    #view-calendar .grid-container { padding: 12px; min-height: 0; min-width: 0; flex: 1; overflow-y: auto; border-radius: 0; border: 0; border-top: 1px solid var(--border-color); box-shadow: none; }
    .year-grid { grid-template-columns: 1fr !important; }
    #trashZone, #liveClock, .nexus-ai-fab { display: none !important; }
    .dashboard-columns { grid-template-columns: 1fr !important; gap: 18px !important; }
    #view-dashboard > .top-bar { padding: 0 0 18px !important; }
    .mobile-quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
    .mobile-quick-actions button { display: flex; align-items: center; gap: 9px; text-align: left; padding: 15px 12px; background: var(--white); border: 1px solid var(--border-color); border-radius: 14px; color: var(--text-main); font-weight: 600; font-size: .8rem; }
    .mobile-quick-actions svg { width: 22px; height: 22px; flex-shrink: 0; color: var(--primary-blue); }
    button, .btn-add, .nav-arrow, .btn-today, .action-icon { min-height: 44px; }
    input:not([type="checkbox"]):not([type="range"]):not([type="color"]), select, textarea { min-width: 0; max-width: 100%; font-size: 16px !important; }
    input[type="checkbox"] { min-width: 22px; min-height: 22px; }
    #dashChecklist > div { gap: 8px !important; }
    #dashChecklist > div > div { min-width: 0; }
    #dashboardContainer input[type="number"] { width: 76px !important; }
    #dashboardContainer input[type="text"] { min-width: 0 !important; }
    .nexus-kanban, #clients-kanban-grid { display: grid !important; grid-template-columns: minmax(0, 1fr) !important; gap: 16px !important; }
    .kanban-col { min-width: 0 !important; }
    .nexus-header { flex-wrap: wrap; gap: 14px; }
    .nexus-hero { padding: 18px; }
    .nexus-hero h1 { font-size: 1.4rem; }
    .nexus-list, #view-expenses > div { max-width: 100%; overflow-x: auto; }
    #view-expenses table { min-width: 500px; }
    #nexus-view-detail { padding: 16px !important; }
    .project-detail-header, .project-detail-columns { flex-shrink: 0; }
    .project-detail-columns { grid-template-columns: minmax(0, 1fr) !important; height: auto !important; gap: 20px !important; }
    .project-detail-header { flex-wrap: wrap; gap: 10px !important; white-space: normal !important; }
    .project-detail-header input { flex: 1; width: 50% !important; min-width: 0 !important; }
    .project-detail-header [id^="folder-nav-"] { width: 100%; overflow-x: auto; }
    .project-detail-header > div:last-child { width: 100%; justify-content: space-between; }
    .project-actions button { background: none; border: 0; min-width: 44px; }
    .project-status-control { width: 100%; padding: 10px; margin-top: 12px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--white); color: var(--text-main); }
    .project-detail-columns > div { min-width: 0; overflow: auto; }
    .project-detail-columns > div:last-child { min-height: 550px; }
    .project-detail-columns > div:last-child > div:first-child { flex-wrap: wrap; gap: 12px; overflow-x: auto; }
    [id^="nexus-canvas-"] { min-height: 400px; touch-action: none; }
    .sticky-note { touch-action: none; }
    .websites-grid, .whiteboard-grid, .kb-grid { grid-template-columns: minmax(0, 1fr) !important; padding: 0 !important; }
    #view-whiteboard > .top-bar { padding: 0 !important; margin-bottom: 16px; gap: 8px !important; }
    #view-whiteboard .view-title { width: auto; font-size: 1.15rem; }
    #view-whiteboard > .top-bar .btn-add { font-size: .8rem; padding: 10px 12px; }
    #view-whiteboard .whiteboard-grid { gap: 12px; max-height: none; overflow: visible; }
    #view-whiteboard .notes-toolbar { flex-wrap: wrap; gap: 8px; }
    #view-whiteboard .notes-toolbar input { flex-basis: 100%; min-height: 44px; }
    #view-whiteboard .post-it { min-height: 0; min-width: 0; padding: 16px; border-radius: 14px; box-shadow: none; }
    #view-whiteboard .post-it:hover { transform: none; }
    #view-whiteboard .note-open { gap: 8px; }
    #view-whiteboard .note-preview-title { font-size: 1rem; padding-right: 32px; }
    #view-whiteboard .note-preview { -webkit-line-clamp: 3; }
    #view-whiteboard .post-it .delete-btn { opacity: 1; top: 4px; right: 4px; width: 44px; height: 44px; font-size: 1.1rem; color: #475569; background: transparent; }
    #view-knowledge > div { flex-direction: column; }
    .kb-sidebar { width: 100% !important; border: 0; }
    .modal-overlay { padding: 12px; z-index: 300 !important; }
    .modal, .nexus-modal-content { width: 100% !important; max-width: 560px !important; max-height: calc(100dvh - 24px); padding: 22px !important; overflow-y: auto !important; border-radius: 20px; }
    .modal h3 { font-size: 1.2rem; }
    .modal button { padding: 10px 12px; }
    .modal > div:last-child { flex-wrap: wrap; gap: 8px !important; }
    #noteModal { padding: 0; top: var(--note-viewport-top, 0); bottom: auto; height: var(--note-viewport-height, 100dvh); }
    #noteModal .modal { display: flex; flex-direction: column; height: 100%; max-height: 100% !important; max-width: none !important; border-radius: 0; margin: 0; padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)) !important; }
    #noteModal .note-editor-header { flex-shrink: 0; margin-bottom: 12px !important; min-height: 44px; }
    #noteModal .note-editor-header button { min-width: 44px; }
    #noteModal #noteContent { flex: 1; min-height: 80px; height: auto !important; margin-bottom: 12px; resize: none; line-height: 1.6; }
    #noteModal .note-color-label { margin: 0 0 8px !important; font-size: .75rem !important; }
    #noteModal #noteColorPicker { flex-shrink: 0; gap: 10px !important; margin-bottom: 12px !important; }
    #noteModal .color-picker-dot { width: 44px; height: 44px; padding: 0; border-radius: 12px; }
    #noteModal .color-picker-dot.active { transform: none; border-width: 3px; }
    #noteModal .note-editor-actions { flex-shrink: 0; }
    #noteModal .note-editor-actions button { flex: 1; justify-content: center; }
    #noteModal .note-editor-actions .btn-add { flex: 2; }
    .side-panel.is-open { display: flex; position: fixed; inset: calc(74px + env(safe-area-inset-top)) 0 calc(76px + env(safe-area-inset-bottom)) auto; width: min(330px, 92vw); z-index: 80; box-shadow: -8px 0 28px #0002; }
    .sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: calc(74px + env(safe-area-inset-top)) 0 calc(76px + env(safe-area-inset-bottom)); height: auto; background: #0f172a66; border: 0; z-index: 70; width: 100%; }
    .app-notice { bottom: calc(88px + env(safe-area-inset-bottom)); }
    .agenda-list { padding: 4px !important; }
    .agenda-task { width: 100%; text-align: left; }
    .mobile-calendar { width: 100%; min-width: 0; flex: 0 0 auto; }
    .mcal-week, .mcal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; margin-bottom: 16px; }
    .mcal-date { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; padding: 6px 0; border: 1px solid transparent; border-radius: 12px; color: var(--text-main); background: transparent; cursor: pointer; }
    .mcal-week .mcal-date { min-height: 72px; }
    .mcal-weekday { color: var(--text-muted); font-size: .67rem; text-transform: uppercase; }
    .mcal-number { font-size: 1rem; font-weight: 700; line-height: 1.1; }
    .mcal-activity { height: 14px; font-size: .62rem; line-height: 14px; color: var(--primary-blue); }
    .mcal-month .mcal-activity { width: 4px; height: 4px; border-radius: 50%; }
    .mcal-month .mcal-activity.has-events { background: var(--primary-blue); }
    .mcal-date.is-today { border-color: var(--primary-blue); }
    .mcal-date[aria-pressed="true"] { background: var(--primary-blue); color: white; border-color: var(--primary-blue); }
    .mcal-date[aria-pressed="true"] .mcal-weekday, .mcal-date[aria-pressed="true"] .mcal-activity { color: white; }
    .mcal-date[aria-pressed="true"] .mcal-activity.has-events { background: white; }
    .mcal-week .mcal-date[aria-pressed="true"] .mcal-activity.has-events { background: transparent; }
    .mcal-month-weekday { text-align: center; font-size: .65rem; font-weight: 600; color: var(--text-muted); padding-bottom: 5px; }
    .mcal-month .mcal-date { min-height: 44px; border-radius: 10px; gap: 4px; padding: 4px 0; }
    .mcal-month .mcal-number { font-size: .85rem; }
    .mcal-day + .mcal-day { margin-top: 24px; }
    .mcal-day-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; }
    .mcal-day-heading h2 { font-size: .85rem; line-height: 1.4; margin: 0; font-weight: 700; }
    .mcal-day-heading h2::first-letter { text-transform: uppercase; }
    .mcal-count { font-size: .7rem; background: var(--hover-bg); color: var(--text-muted); padding: 3px 8px; border-radius: 8px; }
    .mcal-event { --event-color: #3b82f6; display: flex; gap: 12px; align-items: center; padding: 12px; margin: 0 0 8px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--white); color: var(--text-main); cursor: pointer; }
    .mcal-event-time { flex: 0 0 45px; display: flex; flex-direction: column; gap: 4px; font-size: .8rem; }
    .mcal-event-time > span { color: var(--text-muted); font-size: .68rem; }
    .mcal-event-detail { flex: 1; min-width: 0; padding-left: 10px; border-left: 3px solid var(--event-color); display: flex; flex-direction: column; gap: 5px; }
    .mcal-event-title { font-size: .9rem; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
    .mcal-event-kind { font-size: .68rem; color: var(--text-muted); overflow-wrap: anywhere; }
    .mcal-event-arrow { flex-shrink: 0; font-size: 1.2rem; color: var(--text-muted); }
    .mcal-event.is-done .mcal-event-title { text-decoration: line-through; color: var(--text-muted); }
    .mcal-day-note { padding: 8px 10px; background: var(--hover-bg); border-radius: 8px; margin: 0 0 10px; font-size: .75rem; line-height: 1.4; }
    .mcal-empty { padding: 16px 8px; text-align: center; font-size: .85rem; line-height: 1.5; color: var(--text-muted); }
    .mcal-add { border: 1px solid var(--border-color); background: var(--white); color: var(--primary-blue); padding: 8px 14px; border-radius: 10px; margin-top: 12px; }
    .mcal-year-title { font-size: .85rem; margin: 0 0 16px; color: var(--text-muted); }
    .mcal-year { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
    .mcal-month-choice { min-width: 0; min-height: 60px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--white); color: var(--text-main); font-size: .8rem; text-transform: capitalize; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
