/* Ago layout and components. Bootstrap supplies buttons and form controls.
   Colours are variables with a light and a dark set; index.html sets
   data-bs-theme from the device's setting, which also switches Bootstrap. */

:root {
    --ago-bar: #1f2a44;
    --ago-bar-text: #ffffff;
    --ago-surface: #ffffff;
    --ago-pane: #f4f5f8;
    --ago-line: #dfe2ea;
    --ago-hover: #e7e9f0;
    --ago-active: #dce4fb;
    --ago-selected: #eef2fd;
    --ago-accent: #2f5bd8;
    --ago-danger: #c0362c;
    --ago-amber: #8a5a00;
    --ago-muted: #5d6475;
    --ago-check: #6b7285;
    --ago-banner-bg: #fff3cd;
    --ago-banner-text: #5c4400;
    --ago-toast-bg: #2b2f3a;
    --ago-toast-text: #ffffff;
}

[data-bs-theme="dark"] {
    --ago-bar: #141926;
    --ago-bar-text: #e9ecf3;
    --ago-surface: #1b1e26;
    --ago-pane: #15171d;
    --ago-line: #30343f;
    --ago-hover: #262a35;
    --ago-active: #2a3558;
    --ago-selected: #232a40;
    --ago-accent: #7c9cff;
    --ago-danger: #ff8279;
    --ago-amber: #f0b84a;
    --ago-muted: #a3a9b8;
    --ago-check: #8b92a5;
    --ago-banner-bg: #4a3b0a;
    --ago-banner-text: #ffe9a8;
    --ago-toast-bg: #e9ecf3;
    --ago-toast-text: #1b1e26;
    --bs-body-bg: #1b1e26;
}

html, body, #app { height: 100%; }
body { overscroll-behavior-y: none; background: var(--ago-surface); }

/* The template styles assume a white page; make them follow the theme. */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem var(--ago-surface), 0 0 0 0.25rem #258cfb;
}
[data-bs-theme="dark"] a, [data-bs-theme="dark"] .btn-link { color: var(--ago-accent); }

.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }

.shell { display: flex; flex-direction: column; height: 100dvh; }
.shell-body { flex: 1; min-height: 0; }

.app-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.4rem 1rem; background: var(--ago-bar); color: var(--ago-bar-text);
}
.app-bar .account-name { font-weight: 600; }
.app-bar a, .app-bar .btn-link,
[data-bs-theme="dark"] .app-bar a, [data-bs-theme="dark"] .app-bar .btn-link { color: var(--ago-bar-text); }
.app-bar .sign-out { padding: 0; white-space: nowrap; }
.account { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { flex: none; width: 2rem; height: 2rem; border-radius: 50%; object-fit: cover; }
.avatar-initials {
    display: inline-flex; align-items: center; justify-content: center;
    background: #4a5a86; color: #fff; font-size: 0.8rem; font-weight: 600;
}

.ago-status { padding: 2rem 1rem; text-align: center; }

/* Three panes: lists, tasks, and the task detail when one is selected. */
.ago {
    display: grid; grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    height: 100%; background: var(--ago-surface);
}
.ago.has-detail { grid-template-columns: 280px minmax(0, 1fr) 340px; }
.offline-banner {
    grid-column: 1 / -1; padding: 0.4rem 1rem; background: var(--ago-banner-bg); color: var(--ago-banner-text);
    text-align: center;
}
.list-pane, .task-pane, .detail-pane { grid-row: 2; min-height: 0; overflow-y: auto; }
.list-pane { background: var(--ago-pane); border-right: 1px solid var(--ago-line); padding: 0.5rem; }
.task-pane { display: flex; flex-direction: column; overflow: hidden; }
.detail-pane { border-left: 1px solid var(--ago-line); background: var(--ago-surface); padding: 1rem; }

/* List pane */
.list-item {
    display: flex; align-items: center; gap: 0.6rem; width: 100%; color: inherit;
    padding: 0.5rem 0.6rem; border: 0; border-radius: 6px; background: transparent; text-align: left;
}
.list-item:hover { background: var(--ago-hover); }
.list-item.active { background: var(--ago-active); font-weight: 600; }
.list-item .icon, .group-toggle .icon, .pane-form > .icon { color: var(--ago-muted); }
.list-item.active .icon { color: var(--ago-accent); }
.list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--ago-muted); font-size: 0.85rem; }
.list-row { display: flex; align-items: center; background: var(--ago-pane); border-radius: 6px; }
.list-row .list-item { flex: 1; min-width: 0; }
.list-container.grouped { padding-left: 1.2rem; }
.group-header { display: flex; align-items: center; gap: 0.15rem; margin-top: 0.4rem; }
.group-toggle {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.45rem; border: 0; background: transparent;
    text-align: left; padding: 0.35rem 0.4rem; font-weight: 600; color: var(--ago-muted);
}
.icon-button {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    border: 0; background: transparent; color: var(--ago-muted); min-width: 2rem; min-height: 2rem;
    border-radius: 4px;
}
.icon-button:hover:not(:disabled) { background: var(--ago-hover); }
.icon-button:disabled { opacity: 0.4; }
.lists { display: flex; flex-direction: column; min-height: 100%; }
.lists > hr { width: 100%; }
/* The add button stays at the bottom of the pane; its menu opens upwards. */
.pane-add {
    position: sticky; bottom: 0; margin-top: auto; padding-top: 0.5rem; background: var(--ago-pane);
    display: flex; justify-content: flex-end;
}
.pane-form { flex: 1; display: flex; align-items: center; gap: 0.5rem; padding-left: 0.6rem; }
.menu-backdrop { position: fixed; inset: 0; z-index: 10; }
.add-menu {
    position: absolute; right: 0; bottom: 100%; z-index: 11; min-width: 11rem; padding: 0.3rem;
    display: flex; flex-direction: column; border: 1px solid var(--ago-line); border-radius: 8px;
    background: var(--ago-surface); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.add-menu button {
    display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.6rem; border: 0; border-radius: 6px;
    background: transparent; color: inherit; text-align: left;
}
.add-menu button:hover, .add-menu button:focus-visible { background: var(--ago-hover); }
.add-menu .icon { color: var(--ago-muted); }

/* Task pane: header, then the tasks, then the add box pinned to the bottom. */
.task-header { display: flex; align-items: center; gap: 0.6rem; padding: 0.75rem 1rem 0.5rem; }
.task-header .title-icon { font-size: 1.4rem; color: var(--ago-accent); }
.task-header .list-title { flex: 1; min-width: 0; margin: 0; font-size: 1.5rem; font-weight: 600; }
.task-header input.list-title { border-color: transparent; background: transparent; padding-left: 0.25rem; }
.task-header input.list-title:hover, .task-header input.list-title:focus { border-color: var(--ago-line); }
.back-button { display: none; padding-left: 0; text-decoration: none; white-space: nowrap; }
.list-tools {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; padding: 0 1rem 0.5rem;
    color: var(--ago-muted); font-size: 0.9rem;
}
.list-tools label { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.task-scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; padding: 0 1rem 1rem; }
.task-scroller.pulling::before {
    content: "Release to refresh"; display: block; padding: 0.5rem; text-align: center; color: var(--ago-muted);
}
.add-task {
    display: flex; gap: 0.5rem; padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--ago-line); background: var(--ago-surface);
}
.add-task .btn { display: inline-flex; align-items: center; }
.empty { color: var(--ago-muted); padding: 1.5rem 0; text-align: center; }
.section-heading {
    margin: 1rem 0 0.25rem; font-size: 0.85rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--ago-muted);
}
.section-heading.overdue { color: var(--ago-danger); }

.swipe-row { position: relative; overflow: hidden; border-bottom: 1px solid var(--ago-line); }
.swipe-left, .swipe-right { position: absolute; top: 0; bottom: 0; display: flex; visibility: hidden; }
.swipe-active .swipe-left, .swipe-active .swipe-right { visibility: visible; }
.swipe-left { left: 0; }
.swipe-right { right: 0; }
.swipe-left button, .swipe-right button {
    display: flex; align-items: center; gap: 0.35rem; border: 0; padding: 0 0.9rem; color: #fff;
    background: #2f5bd8; font-size: 0.9rem;
}
.swipe-left button + button { background: #8a5a00; }
.swipe-right button.danger { background: #c0362c; }
.swipe-content {
    position: relative; background: var(--ago-surface); touch-action: pan-y; transition: transform 0.15s ease-out;
}
.swipe-content.swiping { transition: none; }

.task-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0.25rem; min-height: 3rem; }
.task-row.selected { background: var(--ago-selected); }
.task-row .form-check-input {
    flex: none; width: 1.3rem; height: 1.3rem; margin: 0; border-radius: 50%; border-color: var(--ago-check);
}
.task-main {
    flex: 1; min-width: 0; display: flex; flex-direction: column; border: 0; background: transparent;
    color: inherit; text-align: left; padding: 0.2rem 0;
}
.task-title { overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 0 0.7rem; color: var(--ago-muted); font-size: 0.8rem; }
.task-meta .overdue { color: var(--ago-danger); }
.task-row.completed { border-bottom: 1px solid var(--ago-line); }
.task-row.completed .task-title { text-decoration: line-through; color: var(--ago-muted); }
.completed-toggle {
    display: flex; align-items: center; gap: 0.4rem; border: 0; background: transparent;
    padding: 0.9rem 0.25rem 0.4rem; font-weight: 600; color: var(--ago-muted);
}

/* Drag-and-drop */
.drag-handle {
    flex: none; display: inline-flex; padding: 0.5rem; color: var(--ago-muted); cursor: grab;
    touch-action: none; user-select: none;
}
.drag-handle[data-disabled] { visibility: hidden; }
.reordering { position: relative; z-index: 2; opacity: 0.9; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
.drop-before { box-shadow: inset 0 3px 0 var(--ago-accent); }
.drop-after { box-shadow: inset 0 -3px 0 var(--ago-accent); }

/* Task detail */
.detail { display: flex; flex-direction: column; gap: 0.75rem; }
.detail-top { display: flex; align-items: center; justify-content: space-between; }
.detail-top h2 { margin: 0; font-size: 1.1rem; }
.detail-title { padding: 0; border-bottom: 0; }
.detail-title .task-title { font-size: 1.1rem; font-weight: 600; }
.detail .form-label {
    display: flex; flex-direction: column; gap: 0.25rem; margin: 0; color: var(--ago-muted); font-size: 0.85rem;
}
.detail-toggles { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.detail .btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; }

/* Toasts sit above the add box. */
.toasts {
    position: fixed; left: 50%; bottom: 4.5rem; transform: translateX(-50%); z-index: 1000;
    display: flex; flex-direction: column; gap: 0.5rem; width: min(92vw, 30rem);
}
.toast-message {
    display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
    padding: 0.7rem 0.9rem; border-radius: 8px; background: var(--ago-toast-bg); color: var(--ago-toast-text);
}
[data-bs-theme="dark"] .toast-message .btn-close-white { filter: none; }

/* Phone: one pane at a time, detail as a full-screen sheet. */
@media (max-width: 767.98px) {
    .ago, .ago.has-detail { grid-template-columns: minmax(0, 1fr); }
    .ago.show-tasks .list-pane, .ago.show-lists .task-pane { display: none; }
    .list-pane { border-right: 0; }
    .back-button { display: inline-flex; align-items: center; gap: 0.2rem; }
    .detail-pane { position: fixed; inset: 0; z-index: 100; border-left: 0; overflow-y: auto; }
}
