@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@400;700&family=Patrick+Hand&display=swap');

/* ── Hand-Drawn design system tokens ──
   Single warm-paper palette per the design spec. The dark/light toggle is
   kept functional but re-themed as "Paper" (light) vs "Chalkboard" (dark) —
   same hand-drawn shapes/typography, inverted brightness. */
:root,
[data-theme="dark"] {
    --brand-navy:   #2d2d2d;
    --brand-blue:   #2d5da1;   /* Secondary Accent — Blue Ballpoint Pen */
    --brand-accent: #ff4d4d;   /* Accent — Red Correction Marker */
    --brand-glow:   rgba(255, 77, 77, 0.15);

    --bg-main:      #1f1f1f;   /* Chalkboard */
    --bg-surface:   #2b2b2b;
    --bg-elevated:  #333333;
    --text-dark:    #fdfbf7;   /* Chalk white */
    --text-muted:   #cbc7bd;
    --card-bg:      #2b2b2b;
    --border-color: #fdfbf7;
    --border-solid: #fdfbf7;

    --input-bg:       #2b2b2b;
    --input-bg-focus: #333333;

    --success-green:  #4caf7d;
    --danger-red:     #ff4d4d;
    --warning-orange: #e0a020;

    --sidebar-width:  260px;
    --radius-card:    20px;
    --radius-btn:     999px;

    --wobbly:    255px 15px 225px 15px / 15px 225px 15px 255px;
    --wobbly-md: 20px 255px 20px 255px / 255px 20px 255px 20px;
    --wobbly-sm: 12px 100px 12px 100px / 100px 12px 100px 12px;
    --hand-shadow:    4px 4px 0px 0px var(--border-solid);
    --hand-shadow-lg: 8px 8px 0px 0px var(--border-solid);
    --hand-shadow-sm: 2px 2px 0px 0px var(--border-solid);
}

/* ── Light theme (the design system's default: Warm Paper) ── */
[data-theme="light"] {
    --brand-navy:   #2d2d2d;
    --brand-blue:   #2d5da1;
    --brand-accent: #ff4d4d;
    --brand-glow:   rgba(255, 77, 77, 0.12);

    --bg-main:      #fdfbf7;   /* Warm Paper */
    --bg-surface:   #ffffff;
    --bg-elevated:  #e5e0d8;   /* Old Paper / Erased Pencil */
    --text-dark:    #2d2d2d;   /* Soft Pencil Black */
    --text-muted:   #6b675f;
    --card-bg:      #ffffff;
    --border-color: #2d2d2d;
    --border-solid: #2d2d2d;

    --input-bg:       #ffffff;
    --input-bg-focus: #ffffff;

    --success-green:  #2f8a5b;
    --danger-red:     #ff4d4d;
    --warning-orange: #c47f00;
}

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

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-solid); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand-accent); }

html { font-size: 16px; }

body {
    font-family: 'Patrick Hand', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-main);
    background-image: radial-gradient(var(--bg-elevated) 1.5px, transparent 1.5px);
    background-size: 24px 24px;
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
    -webkit-text-size-adjust: 100%;
    font-size: 18px;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Kalam', cursive;
    font-weight: 700;
    letter-spacing: 0;
}

/* ── Layout ── */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    color: var(--text-dark);
    padding: 24px 16px;
    height: 100vh;
    position: fixed;
    z-index: 1000;
    top: 0; left: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    border-right: 3px dashed var(--border-solid);
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    transition: background 0.3s, border-color 0.3s, transform 0.3s ease;
    transform: translateX(0);
    will-change: transform;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 20px;
    flex-shrink: 0;
}
.sidebar-logo-text {
    font-family: 'Kalam', cursive;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: -0.3px;
    white-space: nowrap;
    transform: rotate(-1deg);
    display: inline-block;
}

.org-chip {
    background: var(--bg-elevated);
    border: 2px solid var(--border-solid);
    border-radius: var(--wobbly-sm);
    padding: 12px 14px;
    margin-bottom: 20px;
    flex-shrink: 0;
    word-break: break-word;
    transform: rotate(-0.6deg);
}
.org-chip-label {
    color: var(--brand-blue);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 3px;
}
.org-chip-name {
    color: var(--text-dark);
    font-family: 'Kalam', cursive;
    font-size: 14px;
    font-weight: 700;
}
.org-chip-role {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-section-label {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 8px 12px 6px 12px;
    opacity: 0.6;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--wobbly-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 16px;
    font-weight: 400;
    transition: transform 0.1s, background 0.15s, color 0.15s;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 2px solid transparent;
}
.nav-link:hover {
    color: var(--text-dark);
    background: var(--bg-elevated);
    border-color: var(--border-solid);
    transform: rotate(-1deg);
}
.nav-link-active {
    color: var(--text-dark) !important;
    background: var(--brand-accent) !important;
    border: 2px solid var(--border-solid) !important;
    box-shadow: var(--hand-shadow-sm);
}

.nav-icon { font-size: 17px; flex-shrink: 0; }

/* Sidebar footer */
.sidebar-footer {
    border-top: 3px dashed var(--border-solid);
    padding-top: 16px;
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    border-radius: var(--wobbly-sm);
    transition: background 0.2s;
}
.sidebar-user:hover {
    background: var(--bg-elevated);
}
.sidebar-user > div {
    min-width: 0;
    overflow: hidden;
}
.sidebar-user > div > div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-avatar {
    width: 36px; height: 36px;
    border-radius: var(--wobbly-sm);
    background: var(--brand-blue);
    border: 2px solid var(--border-solid);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Kalam', cursive;
    font-weight: 700; font-size: 15px; color: white; flex-shrink: 0;
}
.logout-btn {
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--wobbly-sm);
    display: flex; align-items: center;
    transition: all 0.2s;
    text-decoration: none;
    flex-shrink: 0;
}
.logout-btn:hover { color: var(--brand-accent); background: var(--bg-elevated); }

/* Mobile overlay */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(45,45,45,0.5);
    z-index: 999;
    backdrop-filter: blur(1px);
}

/* ── Main content ── */
.content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 40px;
    min-height: 100vh;
    transition: background 0.3s;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

/* ── Container fluid ── */
.container-fluid {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

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

/* ── Cards ── */
.card {
    background: var(--card-bg);
    padding: 28px;
    border-radius: var(--wobbly-md);
    box-shadow: var(--hand-shadow);
    margin-bottom: 24px;
    border: 3px solid var(--border-solid);
    transition: transform 0.15s, box-shadow 0.15s;
    word-break: break-word;
    overflow-wrap: break-word;
}
.card:hover { transform: rotate(0.3deg); }

/* ── Buttons ── */
.button {
    padding: 11px 22px;
    border-radius: var(--radius-btn);
    cursor: pointer;
    border: 3px solid var(--border-solid);
    background: var(--bg-surface);
    color: var(--text-dark);
    font-weight: 400;
    font-family: 'Patrick Hand', cursive;
    font-size: 16px;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    box-shadow: var(--hand-shadow);
    transition: transform 0.1s, box-shadow 0.1s, background 0.15s, color 0.15s;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.button:hover {
    background: var(--brand-accent);
    color: #fff;
    box-shadow: var(--hand-shadow-sm);
    transform: translate(2px, 2px);
}
.button:active {
    box-shadow: none;
    transform: translate(4px, 4px);
}
.btn-primary {
    background: var(--brand-accent);
    color: #fff;
    border: 3px solid var(--border-solid);
    box-shadow: var(--hand-shadow);
}
.btn-primary:hover {
    background: var(--brand-blue);
    color: #fff;
    box-shadow: var(--hand-shadow-sm);
    transform: translate(2px, 2px);
}
.btn-success {
    background: var(--success-green);
    color: white;
    border: 3px solid var(--border-solid);
    box-shadow: var(--hand-shadow);
}
.btn-success:hover { background: var(--brand-blue); box-shadow: var(--hand-shadow-sm); transform: translate(2px, 2px); }

/* ── Forms ── */
label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
input, textarea, select {
    width: 100%;
    padding: 13px 16px;
    border-radius: var(--wobbly-sm);
    border: 2px solid var(--border-solid);
    background: var(--input-bg);
    color: var(--text-dark);
    margin-bottom: 22px;
    font-family: 'Patrick Hand', cursive;
    font-size: 16px;
    transition: all 0.2s;
    max-width: 100%;
    /* Prevent iOS zoom on focus */
    font-size: max(16px, 16px);
}
input:focus, textarea:focus, select:focus {
    border-color: var(--brand-blue);
    outline: none;
    background: var(--input-bg-focus);
    box-shadow: 0 0 0 3px var(--brand-glow);
}
select option { background: var(--bg-elevated); }

textarea { resize: vertical; min-height: 80px; }
/* ── Password eye toggle ─────────────────────────────────────── */
.pw-field-wrap {
    position: relative;
    width: 100%;
    margin-bottom: 22px;
}
.pw-field-wrap input[type="password"],
.pw-field-wrap input[type="text"].pw-visible {
    padding-right: 46px;
    margin-bottom: 0;
}
.pw-eye-btn {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    line-height: 0;
    color: var(--text-muted);
    font-size: 18px;
    user-select: none;
}
.pw-eye-btn:hover { color: var(--text-dark); }
/* ── Headings ── */
h1, h2, h3 {
    color: var(--text-dark);
    margin-bottom: 15px;
    letter-spacing: -0.03em;
    line-height: 1.2;
    word-break: break-word;
}

h1 { font-size: clamp(1.4rem, 3vw, 2rem); }
h2 { font-size: clamp(1.2rem, 2.5vw, 1.6rem); }
h3 { font-size: clamp(1rem, 2vw, 1.25rem); }

/* ── Kanban ── */
.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 20px;
    min-height: 60vh;
    align-items: flex-start;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}

.kanban-col {
    flex: 1;
    min-width: 260px;
    max-width: 340px;
    background: var(--bg-elevated);
    border-radius: var(--wobbly-md);
    padding: 16px;
    border: 3px dashed var(--border-solid);
    scroll-snap-align: start;
    flex-shrink: 0;
}

.task-list { min-height: 100px; }

.task-card {
    background: var(--card-bg) !important;
    border: 3px solid var(--border-solid);
    border-radius: var(--wobbly-sm);
    box-shadow: var(--hand-shadow);
    padding: 15px;
    margin-bottom: 14px;
    cursor: grab;
    transition: transform 0.15s, box-shadow 0.15s;
    word-break: break-word;
    overflow-wrap: break-word;
    touch-action: none;
}
.task-card:hover {
    transform: translate(-2px, -2px) rotate(-1deg);
    border-color: var(--brand-blue);
    box-shadow: var(--hand-shadow-lg);
}
.kanban-ghost {
    opacity: 0.25;
    background: var(--brand-blue) !important;
    border: 3px dashed var(--brand-blue) !important;
    box-shadow: none;
}
.kanban-chosen {
    transform: rotate(2deg) scale(1.03);
    cursor: grabbing;
    box-shadow: var(--hand-shadow-lg);
}

/* ── Chat (WhatsApp-style messages) ── */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 420px;
    overflow-y: auto;
    padding: 16px 12px;
    margin-bottom: 20px;
    border-radius: var(--wobbly-sm);
    background-color: var(--bg-elevated);
    background-image: radial-gradient(var(--border-solid) 1px, transparent 1px);
    background-size: 18px 18px;
    background-blend-mode: overlay;
    border: 2px dashed var(--border-solid);
    scroll-behavior: smooth;
}
.chat-empty { text-align: center; color: var(--text-muted); font-size: 14px; font-style: italic; margin: auto; padding: 20px 0; }

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    margin: 6px 0;
}
.chat-row-me   { justify-content: flex-end; }
.chat-row-them { justify-content: flex-start; }

.chat-row-new { animation: chatMessageIn 0.28s ease-out; }
@keyframes chatMessageIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--brand-blue);
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-bubble {
    position: relative;
    max-width: 75%;
    padding: 8px 12px 18px 12px;
    border-radius: var(--wobbly-sm);
    border: 2px solid var(--border-solid);
    font-size: 16px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
    box-shadow: var(--hand-shadow-sm);
}
.chat-bubble-me {
    background: var(--brand-accent);
    color: #fff;
    transform: rotate(0.5deg);
}
.chat-bubble-them {
    background: var(--bg-surface);
    color: var(--text-dark);
    transform: rotate(-0.5deg);
    border: 2px solid var(--border-solid);
}
.chat-sender {
    font-size: 12px;
    font-weight: bold;
    color: var(--brand-blue);
    margin-bottom: 2px;
}
.chat-text { white-space: pre-wrap; }
.chat-image {
    max-width: 100%;
    border-radius: var(--wobbly-sm);
    margin-top: 8px;
    display: block;
    border: 2px solid var(--border-solid);
}
.chat-time {
    position: absolute;
    bottom: 4px;
    right: 12px;
    font-size: 11px;
    opacity: 0.7;
}
.chat-bubble-them .chat-time { color: var(--text-dark); }

.chat-input-row { display: flex; gap: 8px; margin-bottom: 20px; }
.chat-input-row input {
    flex: 1;
    padding: 14px;
    border-radius: var(--wobbly-sm);
    border: 2px solid var(--border-solid);
    background: var(--input-bg);
    color: var(--text-dark);
    font-size: 16px;
    margin-bottom: 0;
}
.chat-input-row button {
    background: var(--brand-accent);
    color: white;
    border: 2px solid var(--border-solid);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: var(--hand-shadow-sm);
    transition: transform 0.1s, opacity 0.15s;
}
.chat-input-row button:hover:not(:disabled) { transform: translate(1px, 1px); }
.chat-input-row button:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 480px) {
    .chat-bubble { max-width: 85%; }
    .chat-thread { max-height: 360px; }
}

/* ── Progress ── */
.progress-container { background: var(--bg-elevated); border-radius: 999px; height: 8px; overflow: hidden; border: 1px solid var(--border-solid); }
.progress-fill {
    background: var(--brand-blue);
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}
/* ── Status pill (My Tasks / All Tasks / Board / Team Stats) ── */
.status-pill {
    display: inline-flex; align-items: center; gap: 4px;
    border-radius: 999px; padding: 4px 12px; font-size: 12px; font-weight: 700; white-space: nowrap;
    border: 2px solid currentColor;
}
.status-pill.pending     { background: rgba(224,160,32,0.12); color: var(--warning-orange); }
.status-pill.in_progress { background: rgba(45,93,161,0.12);  color: var(--brand-blue); }
.status-pill.completed   { background: rgba(47,138,91,0.12);  color: var(--success-green); }
.status-pill.overdue     { background: rgba(255,77,77,0.12);  color: var(--danger-red); }
.status-pill.neutral     { background: var(--bg-elevated);    color: var(--text-muted); border-color: var(--border-solid); }

/* ── Sticky note card (My Board / All Tasks) ── */
.sticky-note {
    background: var(--bg-surface); border: 2px solid var(--border-solid);
    border-radius: var(--wobbly-sm); padding: 14px 16px; width: 220px;
    box-shadow: var(--hand-shadow-sm);
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.15s;
}
.sticky-note:hover { border-color: var(--brand-blue); transform: rotate(-1deg); box-shadow: var(--hand-shadow); }
.sticky-title { color: var(--brand-blue); font-family: 'Kalam', cursive; font-weight: 700; font-size: 16px; margin-bottom: 10px; }

/* ── Subtask mini progress bar ── */
.subtask-progress-label { display:flex; justify-content:space-between; font-size:11px; color:var(--brand-accent); font-weight:600; margin-bottom:4px; }
.subtask-progress-track { background: var(--bg-main); border-radius:6px; height:6px; overflow:hidden; margin-bottom:6px; }
.subtask-progress-fill  { background: var(--brand-accent); height:100%; border-radius:6px; transition:width .4s ease; }

/* ── Collapsible subtask list (native <details>, no JS needed) ── */
.subtask-list summary { cursor:pointer; font-size:11px; color:var(--text-muted); list-style:none; margin-bottom:6px; }
.subtask-list summary::-webkit-details-marker { display:none; }
.subtask-list summary::before { content:"▸ "; }
.subtask-list[open] summary::before { content:"▾ "; }
.subtask-item { font-size:11px; padding:2px 0 2px 12px; }
.subtask-item.done { color: var(--text-muted); text-decoration: line-through; }

/* ── Self/member stat card (My Tasks / Team Stats) ── */
.stat-card { background: var(--bg-surface); border: 2px solid var(--border-solid); border-radius: var(--wobbly-sm); padding:20px 22px; box-shadow: var(--hand-shadow-sm); }
.stat-progress-track { background: var(--bg-elevated); border-radius:999px; height:8px; overflow:hidden; display:flex; border: 1px solid var(--border-solid); }
.stat-progress-completed  { background: var(--success-green); height:100%; border-radius:999px 0 0 999px; }
.stat-progress-inprogress { background: var(--brand-blue); height:100%; }
/* ── Auth pages ── */
.auth-card, .guest-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
    background-image: radial-gradient(circle at 50% 30%, var(--brand-glow) 0%, transparent 60%);
    padding: 20px;
}

/* ── Dashboard header ── */
.dashboard-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 24px;
    padding: 12px 16px;
    background: var(--brand-glow);
    border: 2px dashed var(--border-solid);
    border-radius: var(--wobbly-sm);
    width: fit-content;
    max-width: 100%;
    flex-wrap: wrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-dot.green { background: var(--success-green); box-shadow: 0 0 8px var(--success-green); }


/* Sidebar close button — only visible on mobile */
.sidebar-close-btn { display: none !important; }
@media (max-width: 768px) {
    .sidebar-close-btn { display: flex !important; }
    /* Sidebar needs position relative so the close btn can be absolute */
    .sidebar { position: fixed; }
}

/* ─────────────────────────────────────────────────
   RESPONSIVE BREAKPOINTS
───────────────────────────────────────────────── */

/* ── Large laptops / desktops (1440px+) ── */
@media (min-width: 1440px) {
    .content { padding: 48px 56px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

/* ── Medium laptops (1024px – 1279px) ── */
@media (max-width: 1279px) {
    :root { --sidebar-width: 230px; }
    .content { padding: 32px 28px; }
    .card { padding: 22px; }
}

/* ── Small laptops / large tablets (900px – 1023px) ── */
@media (max-width: 1023px) {
    :root { --sidebar-width: 210px; }
    .content { padding: 28px 20px; }
    .card { padding: 20px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
    .kanban-col { min-width: 230px; }
}

/* ── Tablet (768px – 899px) ── */
@media (max-width: 899px) {
    :root { --sidebar-width: 190px; }
    .content { padding: 24px 16px; }
    .card { padding: 18px; }
    .sidebar { padding: 20px 12px; }
    .sidebar-logo-text { font-size: 14px; }
    .nav-link { font-size: 13px; padding: 9px 10px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
    .button { padding: 10px 18px; font-size: 12px; }
}

/* ── Mobile & small tablets (max 768px) ── */
@media (max-width: 768px) {
    /* Sidebar collapses off-screen */
    .sidebar {
        left: 0;
        transform: translateX(-110%);
        transition: transform 0.3s ease;
        width: 260px;
        padding: 20px 14px;
    }

    /* Sidebar opens when checkbox is checked */
    #nav-toggle:checked ~ .app-layout .sidebar { transform: translateX(0); }
    #nav-toggle:checked ~ #sidebar-overlay { display: block; }

    /* Content full-width, top padding for top bar */
    .content {
        margin-left: 0;
        padding: 16px;
        padding-top: 72px;
        overflow-x: hidden;
    }

    /* Mobile top bar always visible */
    .mobile-top-bar {
        display: flex !important;
        align-items: center;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: 60px;
        background: var(--bg-elevated);
        border-bottom: 3px dashed var(--border-solid);
        padding: 0 16px;
        z-index: 998;
    }

    /* Grid stacks to single column */
    .grid { grid-template-columns: 1fr; gap: 14px; }

    /* Cards slightly tighter */
    .card { padding: 16px; margin-bottom: 16px; }

    /* Full-width buttons on forms */
    .button { padding: 12px 20px; font-size: 13px; }

    /* Auth cards full-width on small screens */
    .auth-card > .card,
    .guest-wrapper > .card {
        width: 100% !important;
        max-width: 420px;
        padding: 28px 20px !important;
        margin: 0 !important;
    }

    /* Kanban horizontal scroll with snapping */
    .kanban-board {
        gap: 12px;
        padding-bottom: 16px;
        scroll-padding-left: 16px;
    }
    .kanban-col {
        min-width: 78vw;
        max-width: 86vw;
    }

    /* Project header stacks */
    .card > div[style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    /* Activity panel full-width when toggled */
    #activity-panel {
        width: 100% !important;
    }

    h1 { font-size: 1.4rem; }
    h2 { font-size: 1.2rem; }
    h3 { font-size: 1.05rem; }

    /* Comment boxes full width */
    /* Team page action buttons wrap */
    .button[style*="font-size:12px"] {
        padding: 8px 12px;
        font-size: 11px !important;
    }

    /* Dashboard owner-filter full-width on mobile */
    #owner-filter { width: 100%; max-width: 100%; }

    /* Filter tabs don't overflow */
    .filter-tab { padding: 8px 14px; font-size: 12px; }
}

/* ── Very small phones (max 375px) ── */
@media (max-width: 375px) {
    .content { padding: 12px; padding-top: 68px; }
    .card { padding: 14px; }
    .kanban-col { min-width: 90vw; max-width: 94vw; }
    h1 { font-size: 1.25rem; }
    .button { padding: 10px 14px; font-size: 12px; }
    input, textarea, select { padding: 11px 12px; }
    /* Date grid stacks on tiny screens */
    .date-grid-2col { grid-template-columns: 1fr !important; }
}

/* ── Touch devices — larger tap targets ── */
@media (hover: none) and (pointer: coarse) {
    .nav-link { padding: 13px 12px; }
    .button { min-height: 44px; }
    input, textarea, select { min-height: 44px; }
    .task-card { padding: 16px; margin-bottom: 14px; }
    .logout-btn { padding: 10px; }
}

/* ── Kanban scrollbar styling ── */
.kanban-board::-webkit-scrollbar { height: 6px; }
.kanban-board::-webkit-scrollbar-track { background: transparent; }
.kanban-board::-webkit-scrollbar-thumb { background: var(--border-solid); border-radius: 10px; }

/* ── Activity panel scrollbar ── */
#activity-panel::-webkit-scrollbar { width: 4px; }
#activity-panel::-webkit-scrollbar-thumb { background: var(--border-solid); border-radius: 999px; }

/* ── Prevent text overflow everywhere ── */
p, span, div, a, li, td, th, label {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ── Images never overflow ── */
img { max-width: 100%; height: auto; }

/* ── Tables scroll on small screens ── */
/* NOTE: do NOT set display:block globally — it breaks table-layout:fixed on calendar.
   Instead, wrap scrollable tables in a div.table-scroll-wrapper. */
.table-scroll-wrapper { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll-wrapper table { width: 100%; }
/* Only non-calendar tables get block display for scrolling */
table:not(.cal-month-table) { max-width: 100%; overflow-x: auto; }

/* ── Flex-wrap helpers for inline chips ── */
[style*="display:flex"][style*="flex-wrap:wrap"],
[style*="display: flex"][style*="flex-wrap: wrap"] {
    flex-wrap: wrap;
}
/* ─── NEW VIEW TOGGLE SYSTEM ─── */
.toggle-switcher-row {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    gap: 8px;
}

.toggle-view-btn {
    background: var(--bg-surface);
    border: 2px solid var(--border-solid);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--wobbly-sm);
    font-size: 14px;
    font-weight: 400;
    font-family: 'Patrick Hand', cursive;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.toggle-view-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-dark);
}

.toggle-view-btn.active-mode {
    background: var(--brand-accent);
    color: #ffffff;
    border-color: var(--border-solid);
    box-shadow: var(--hand-shadow-sm);
}

/* Dynamic Grid Layout Overrides */
.grid-matrix-mode {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)) !important;
    gap: 20px !important;
    flex-direction: unset !important;
}

.grid-matrix-mode .kanban-col {
    min-width: 0 !important;
    max-width: 100 !important;
    width: 100% !important;
    background: rgba(15, 23, 42, 0.4) !important;
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
}
/* ─── PROJECTS WRAPPER LAYOUTS ─── */
.projects-container {
    margin-top: 24px;
    transition: all 0.3s ease;
}

/* Grid Layout Mode */
.projects-container.view-grid {
    display: grid;
    /* Automatically creates columns that break down nicely to mobile sizes */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

/* Row List Layout Mode */
.projects-container.view-normal {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── CARD LAYOUT OPTIMIZATIONS ─── */
.project-card {
    background: var(--bg-elevated);
    border: 3px solid var(--border-color);
    border-radius: var(--wobbly-sm);
    box-shadow: var(--hand-shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 160px; /* Uniform height for grid items */
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.project-card:hover {
    transform: translate(-2px, -2px) rotate(-1deg);
    border-color: var(--brand-blue);
    box-shadow: var(--hand-shadow-lg);
}

/* Structural changes when the parent turns into a Row List */
.projects-container.view-normal .project-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    min-height: auto;
    padding: 16px 24px;
}
/* ─────────────────────────────────────────────────
   DASHBOARD WORKSPACE DYNAMIC SYSTEM 
───────────────────────────────────────────────── */

/* Master Wrapper Configuration */
.projects-layout-wrapper {
    transition: all 0.25s ease-in-out;
    width: 100%;
}

/* Grid Variant Presenter */
.projects-layout-wrapper.view-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

/* Row List Variant Presenter */
.projects-layout-wrapper.view-normal {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Responsive Adaptive Component Modifiers */
.projects-layout-wrapper.view-normal .project-card {
    display: flex;
    flex-direction: column;
    padding: 8px 0 0 0;
}

/* Left-side accent indicator bar adjustment for Row Mode */
.projects-layout-wrapper.view-normal .project-card-accent {
    height: auto;
    width: 4px;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    background: var(--brand-blue);
}
.logout-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    padding: 8px;
    display: inline-flex;
    align-items: center;
}
input[type="checkbox"] {
    accent-color: var(--success-green);
    border-radius: 50%;
    width: 12px;
    height: 12px;
}
/* Fix structural offsets caused by absolute positioning accent line */
.projects-layout-wrapper.view-normal .project-card > div[style*="padding:24px;"] {
    padding: 20px 24px 20px 28px !important;
}

@media (min-width: 900px) {
    /* Side-by-side split action rows for broad view row layout panels */
    .projects-layout-wrapper.view-normal .project-card > div[style*="padding:24px;"] {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}