:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --border: #dfe1e6;
    --text: #172b4d;
    --muted: #6b778c;
    --primary: #0052cc;
    --primary-dark: #0747a6;
    --today: #e6fcff;
    --today-border: #00b8d9;
    --danger: #de350b;
    --radius: 6px;
    --status-new: #c62828;
    --status-open: #d9822b;
    --status-closed: #2e7d32;
    --status-moved: #5e6c84;
    --overdue-accent: #de350b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); }

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 360px;
    box-shadow: 0 1px 3px rgba(9, 30, 66, 0.1);
}

.auth-card-wide { width: 560px; }

.auth-card h1 { margin-top: 0; }

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

.alert { padding: 0.6rem 0.8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #ffebe6; color: var(--danger); border: 1px solid #ffbdad; }

form label { display: block; font-size: 0.85rem; margin-bottom: 0.3rem; color: var(--muted); }

input[type="email"], input[type="text"], textarea, select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-bottom: 1rem;
    font-family: inherit;
}

button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    background: var(--primary);
    color: #fff;
}

button:hover { background: var(--primary-dark); }
button.secondary { background: #42526e; }
button.link-button { background: none; color: var(--muted); padding: 0; text-decoration: underline; }

.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.setup-panel h2 { font-size: 1rem; margin-top: 0; }

/* Board page */
.board-page { min-height: 100vh; display: flex; flex-direction: column; }

.board-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.board-header h1 { font-size: 1.15rem; margin: 0; display: inline-block; }
.board-header-left { display: flex; align-items: baseline; gap: 0.9rem; }
.join-code { font-size: 0.8rem; color: var(--muted); }
.board-header-right { display: flex; align-items: center; gap: 1rem; }
.filter-label { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.4rem; }
.filter-label select { margin-bottom: 0; width: auto; }
.me { font-size: 0.85rem; color: var(--muted); }
.add-task-button { font-weight: 600; white-space: nowrap; }

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.filter-bar-label { font-size: 0.85rem; color: var(--muted); }

.day-filters { display: flex; gap: 0.4rem; }
.day-filters button {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}
.day-filters button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.day-filters button:hover { background: #dfe1e6; }
.day-filters button.active:hover { background: var(--primary-dark); }

.status-filters { display: flex; gap: 0.4rem; }
.status-filters button {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}
.status-filters button:hover { background: #dfe1e6; }
.status-filters button.active { color: #fff; border-color: transparent; }
.status-filters button[data-status=""].active { background: var(--primary); }
.status-filters button[data-status="new"].active { background: var(--status-new); }
.status-filters button[data-status="open"].active { background: var(--status-open); }
.status-filters button[data-status="new,open"].active { background: linear-gradient(90deg, var(--status-new), var(--status-open)); }
.status-filters button[data-status="closed"].active { background: var(--status-closed); }

.filter-select {
    width: 150px;
    margin-bottom: 0;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}
.filter-select:first-of-type { margin-left: auto; }

.search-filter {
    width: 220px;
    margin-bottom: 0;
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
}

.board {
    flex: 1;
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    align-items: flex-start;
}

.board-loading { color: var(--muted); padding: 2rem; }

.board-column {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 160px);
}

.undated-column { border-color: #998dd9; background: #f3f0fc; }
.board-column.is-today { border-color: var(--today-border); background: var(--today); }

/* Overdue is a fixed-size summary column, exempt from the day-filter size tiers */
.overdue-column { border-color: var(--overdue-accent); background: #fff5f3; flex-basis: 260px !important; }
.overdue-column .column-header { color: var(--overdue-accent); }

.column-header {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: inherit;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}

.column-list {
    padding: 0;
    overflow-y: auto;
    flex: 1;
    min-height: 60px;
}

/* Squares are literal square blocks (1:1 aspect ratio) stacked flush, like building blocks */
.square-card {
    position: relative;
    background: var(--status-new);
    color: #fff;
    border: none;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 0;
    padding: 0.5rem 0.65rem;
    margin: 0;
    cursor: grab;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.square-notes-count {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 0, 0, 0.35);
    padding: 1px 5px;
    border-radius: 8px;
    line-height: 1.3;
}
.square-notes-count:empty { display: none; }

.square-move-button {
    display: none;
    position: absolute;
    bottom: 4px;
    left: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 0, 0, 0.35);
    border: none;
    padding: 2px 7px;
    border-radius: 8px;
    line-height: 1.4;
    cursor: pointer;
}
.square-move-button:hover { background: rgba(0, 0, 0, 0.55); }
.square-card.is-overdue .square-move-button { display: inline-block; }

.column-list .square-card:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.column-list .square-card:last-child { border-bottom: none; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }

.square-card:active { cursor: grabbing; }
.square-ghost { opacity: 0.4; }
.square-fallback { opacity: 0.9; box-shadow: 0 4px 10px rgba(9, 30, 66, 0.35); }

.square-card.status-new { background: var(--status-new); }
.square-card.status-open { background: var(--status-open); }
.square-card.status-closed { background: var(--status-closed); }
.square-card.status-moved { background: var(--status-moved); }

.square-card.filtered-out { display: none; }

.square-number { font-size: 0.7rem; font-weight: 700; color: rgba(255, 255, 255, 0.85); flex-shrink: 0; }
.square-title {
    font-size: 0.85rem;
    margin-top: 0.15rem;
    font-weight: 600;
    color: #fff;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.square-assignee { font-size: 0.72rem; color: rgba(255, 255, 255, 0.85); margin-top: 0.2rem; flex-shrink: 0; }
.square-description {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 0.3rem;
    white-space: pre-wrap;
    overflow: hidden;
    flex: 1;
}

/* Size variants: every square is a true square (1:1) — fewer days shown = bigger blocks = more info fits */
.board.size-tiny .board-column { flex-basis: 76px; }
.board.size-tiny .square-card { padding: 0.3rem; align-items: center; justify-content: center; }
.board.size-tiny .square-number { font-size: 0.9rem; }
.board.size-tiny .square-title,
.board.size-tiny .square-assignee,
.board.size-tiny .square-description { display: none; }

.board.size-small .board-column { flex-basis: 140px; }
.board.size-small .square-assignee,
.board.size-small .square-description { display: none; }
.board.size-small .square-title { -webkit-line-clamp: 4; }

.board.size-medium .board-column { flex-basis: 210px; }
.board.size-medium .square-description { display: none; }

.board.size-large .board-column { flex-basis: 270px; }

.board.size-xlarge .board-column { flex-basis: 330px; }
.board.size-xlarge .square-card { padding: 0.75rem; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(9, 30, 66, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--panel);
    border-radius: var(--radius);
    width: 480px;
    max-width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(9, 30, 66, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }

.modal-close {
    background: none;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0;
}
.modal-close:hover { background: none; color: var(--text); }

.modal-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-tab {
    background: none;
    color: var(--muted);
    border-radius: 0;
    padding: 0.6rem 0.75rem;
    border-bottom: 2px solid transparent;
    font-size: 0.9rem;
}
.modal-tab:hover { background: none; color: var(--text); }
.modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.modal-tab[hidden] { display: none; }

.modal-pane { padding: 1.1rem 1.25rem 1.25rem; }
.modal-pane[hidden] { display: none; }

.modal-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.4rem; }

.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.log-list li { border-bottom: 1px solid var(--border); padding-bottom: 0.6rem; }
.log-details { display: block; font-size: 0.9rem; white-space: pre-wrap; }
.log-meta { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }

.note-form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.note-form textarea { margin-bottom: 0; }
.note-form button { align-self: flex-end; }

/* Admin */
.admin-main { max-width: 720px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.admin-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
}
.admin-section h2 { margin-top: 0; margin-bottom: 0.3rem; font-size: 1.1rem; }

.admin-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; }
.admin-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }

.admin-badge {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.4rem;
}

.admin-inline-form, .admin-add-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.admin-inline-form input, .admin-add-form input {
    margin-bottom: 0;
    flex: 1;
}
.admin-inline-form button, .admin-add-form button {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    white-space: nowrap;
}
.admin-add-form { margin-top: 1rem; }
