:root {
    --color-bg: #ffffff;
    --color-surface: #f7f7f7;
    --color-border: #e0e0e0;
    --color-text: #111111;
    --color-text-muted: #6b6b6b;
    --color-accent: #111111;
    --color-accent-hover: #333333;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #121212;
        --color-surface: #1e1e1e;
        --color-border: #3a3a3a;
        --color-text: #ececec;
        --color-text-muted: #a0a0a0;
        --color-accent: #ececec;
        --color-accent-hover: #cfcfcf;
    }
}

/* Explicit manual choice — set via the toggle in the header — always wins
   over the OS-level prefers-color-scheme media query above, regardless of
   which one appears later in the file, since an attribute selector is more
   specific than a bare :root either way. */
:root[data-theme="dark"] {
    --color-bg: #121212;
    --color-surface: #1e1e1e;
    --color-border: #3a3a3a;
    --color-text: #ececec;
    --color-text-muted: #a0a0a0;
    --color-accent: #ececec;
    --color-accent-hover: #cfcfcf;
}

:root[data-theme="light"] {
    --color-bg: #ffffff;
    --color-surface: #f7f7f7;
    --color-border: #e0e0e0;
    --color-text: #111111;
    --color-text-muted: #6b6b6b;
    --color-accent: #111111;
    --color-accent-hover: #333333;
}

* {
    box-sizing: border-box;
    border-radius: 0 !important;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.55;
    height: 100vh;
    /* Inherited by everything — a long unbroken token (URL, id, run-on
       text with no spaces) breaks onto the next line instead of
       overflowing its container. */
    overflow-wrap: break-word;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--color-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--color-text-muted);
}

.logout-form {
    display: inline;
    margin: 0;
    padding: 0;
}

.link-button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    cursor: pointer;
    color: var(--color-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.link-button:hover {
    color: var(--color-text-muted);
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.75rem;
    border-bottom: 1px solid var(--color-border);
}

.site-header .brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--color-text);
    text-decoration: none;
}

.site-header nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.menu-btn {
    display: none;
}

.locale-toggle a,
.theme-toggle a {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 700;
}

.locale-toggle a.active,
.theme-toggle a.active {
    color: var(--color-text);
}

.locale-toggle a:not(:last-child)::after,
.theme-toggle a:not(:last-child)::after {
    content: "/";
    margin: 0 0.25rem;
    color: var(--color-border);
}

.locale-toggle-standalone {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.theme-toggle-standalone {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
}

.app-shell {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sidebar-toggle-checkbox {
    display: none;
}

.sidebar {
    width: 200px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 1rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-nav a {
    padding: 0.55rem 0.6rem;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.sidebar-nav a:hover {
    background: var(--color-surface);
    color: var(--color-text);
}

.sidebar-nav a.active {
    background: var(--color-text);
    color: var(--color-bg);
}

.sidebar-backdrop {
    display: none;
}

main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 3rem 2.5rem;
    overflow-y: auto;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .site-header {
        padding: 1rem 1.25rem;
        gap: 0.75rem;
    }

    .menu-btn {
        display: inline-block;
        font-size: 1.3rem;
        cursor: pointer;
        line-height: 1;
    }

    .site-header .brand {
        display: none;
    }

    .site-header nav {
        gap: 0.6rem;
        font-size: 0.8rem;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -240px;
        bottom: 0;
        width: 220px;
        background: var(--color-bg);
        z-index: 50;
        transition: left 0.2s ease;
        overflow-y: auto;
    }

    .sidebar-toggle-checkbox:checked ~ .sidebar {
        left: 0;
    }

    .sidebar-toggle-checkbox:checked ~ .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 40;
    }

    main {
        padding: 1.75rem 1.25rem;
    }
}

@media (max-width: 480px) {
    .user-email {
        display: none;
    }
}

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
    letter-spacing: -0.01em;
}

h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 2.5rem 0 0.5rem;
    letter-spacing: -0.01em;
}

p {
    color: var(--color-text-muted);
}

.btn {
    display: inline-block;
    padding: 0.65rem 1.4rem;
    background: var(--color-accent);
    color: var(--color-bg);
    font-weight: 600;
    font-size: 0.875rem;
    border: 1px solid var(--color-accent);
    cursor: pointer;
}

.btn:hover {
    background: var(--color-accent-hover);
    border-color: var(--color-accent-hover);
    color: var(--color-bg);
    text-decoration: none;
}

.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    border-color: var(--color-text);
    color: var(--color-text);
    background: transparent;
}

.card {
    border: 1px solid var(--color-border);
    padding: 1.5rem;
    background: var(--color-surface);
}

.mcp-connector {
    margin-bottom: 1.5rem;
}

.mcp-connector p {
    margin: 0 0 0.5rem;
}

.mcp-connector p:last-child {
    margin-bottom: 0;
}

.mcp-connector ul {
    margin: 0;
    padding-left: 1.25rem;
}

.mcp-connector li {
    margin-bottom: 0.35rem;
}

.mcp-connector li:last-child {
    margin-bottom: 0;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--color-text);
    color: var(--color-bg);
}

.badge-in_progress {
    background: transparent;
    color: #b45309;
    border: 1px solid #b45309;
}

.badge-limitation {
    background: transparent;
    color: #b91c1c;
    border: 1px solid #b91c1c;
}

.badge-done {
    background: transparent;
    color: #15803d;
    border: 1px solid #15803d;
}

/* Owner-only "you have an unread note" alert — solid fill (vs. the outline
   status badges) plus a pulsing ring so it actually catches the eye in a
   busy table row, not just another quiet pill. */
.badge-note-alert {
    display: block;
    width: max-content;
    margin-top: 0.35rem;
    background: #b45309;
    color: #fff;
    border: 1px solid #b45309;
    animation: note-alert-pulse 1.6s ease-in-out infinite;
}

@keyframes note-alert-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(180, 83, 9, 0.55);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(180, 83, 9, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .badge-note-alert {
        animation: none;
    }
}

/* Quick visual identification of task vs. entry references wherever they
   might otherwise be ambiguous (table rows, AI responses) — a deliberate,
   explicit exception to the sharp-corners-only rule enforced globally
   below (border-radius: 0 !important on *), so this needs !important too
   just to take effect at all. */
.task-ref::before,
.entry-ref::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 0.4em;
    vertical-align: middle;
    border-radius: 50% !important;
}

.task-ref::before {
    background: #b45309;
}

.entry-ref::before {
    background: #1d4ed8;
}

/* Bigger dot for the "Task |" / "Entry" label on the detail pages — same
   colors, just sized to actually read as a title next to h1-sized text. */
.task-ref.ref-title::before,
.entry-ref.ref-title::before {
    width: 14px;
    height: 14px;
}

input, select, textarea, button {
    font-family: inherit;
    font-size: 0.9rem;
}

input[type="text"], input[type="email"], textarea, select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    width: 100%;
}

textarea {
    resize: vertical;
    min-height: 160px;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-text);
}

.auth-screen {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 360px;
    border: 1px solid var(--color-border);
    padding: 2.5rem 2rem;
    text-align: center;
}

.auth-card h1 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.auth-card .auth-subtitle {
    font-size: 0.9rem;
    margin: 0 0 1.75rem;
}

.auth-card .btn {
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

/* Formatted date+time (format-dates.js) reads as "MM/DD/YYYY H:MM AM/PM" —
   never let it wrap onto a second line, in a table cell or anywhere else. */
time[data-iso] {
    white-space: nowrap;
}

/* Tasks table columns, largest to smallest: description, title, user,
   status, created, actions. When the admin-only "user" column isn't
   present, table-layout: fixed scales the rest to fill 100% anyway, so
   the relative proportions still hold. */
.col-description {
    width: 30%;
}

.col-title {
    width: 20%;
}

.col-status {
    width: 13%;
}

.col-created {
    width: 13%;
}

.col-actions {
    width: 9%;
    min-width: 175px;
}

/* Timeline table columns, largest to smallest: text, task, user, date, type. */
.col-text {
    width: 34%;
}

.col-task {
    width: 22%;
}

.col-date {
    width: 15%;
}

.col-type {
    width: 14%;
}

.col-user {
    width: 15%;
}

/* Notes table: note text gets the remaining space, by/created shrink to
   their content via the classic width:1%+nowrap auto-layout trick. */
.notes-table {
    margin-top: 0.75rem;
}

/* .page-header already supplies the gap above this table via its own
   margin-bottom; .table's default margin-top would stack on top of it
   since .table-scroll's overflow-x:auto blocks margin collapsing. */
#task-entries .table {
    margin-top: 0;
}

.col-note {
    width: auto;
}

.col-note-by,
.col-note-created,
.col-note-actions {
    width: 1%;
    white-space: nowrap;
}

.notes-form {
    display: flex;
    align-items: stretch;
    gap: 0.75rem;
    margin: 0 0 1.5rem;
}

.notes-form textarea {
    flex: 1;
    min-height: 0;
    height: 4.5rem;
}

.notes-form .btn {
    white-space: nowrap;
}

.wrap-cell {
    max-width: 240px;
    white-space: normal;
    word-wrap: break-word;
}

.description-cell {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.title-cell {
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-muted {
    color: var(--color-text-muted);
}

.table th {
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.invite-form {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.invite-form .field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    min-width: 180px;
}

.invite-form label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.invite-form .btn {
    flex-shrink: 0;
}

.char-count {
    align-self: flex-end;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 0.2rem;
}



.form-error {
    color: #b91c1c;
    font-size: 0.85rem;
    margin: 0 0 0.75rem;
}

.btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
}

.actions-cell {
    text-align: right;
    white-space: nowrap;
    vertical-align: middle;
}

.inline-actions {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
}

.entry-actions {
    margin-top: 1.5rem;
}

.role-select {
    width: auto;
    padding: 0.3rem 0.5rem;
}

.timeline-date {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1,
.page-header h2 {
    margin: 0;
}

.header-filter select {
    width: auto;
    min-width: 160px;
}

.entries-header {
    align-items: flex-end;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.section-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2rem 0 0;
}

.truncate {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-detail {
    margin-top: 1.5rem;
}

.entry-from {
    margin: 0 0 1rem;
    font-size: 0.85rem;
}

.entry-body {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    margin-top: 1rem;
    color: var(--color-text);
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.chat-message-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 0.35rem;
}

.chat-message-body {
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.thinking-dots {
    display: inline-flex;
    gap: 0.3rem;
    align-items: center;
    height: 1rem;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    animation: thinking-pulse 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking-pulse {
    0%, 80%, 100% {
        opacity: 0.25;
        transform: scale(0.75);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.chat-message-body p {
    margin: 0 0 0.75rem;
}

.chat-message-body ul {
    margin: 0 0 0.75rem;
    padding-left: 1.25rem;
}

.chat-message-body li {
    margin-bottom: 0.3rem;
}

.chat-message-body p:last-child,
.chat-message-body ul:last-child {
    margin-bottom: 0;
}

.chat-message-body a {
    color: var(--color-text);
}

.chat-message-body .badge {
    font-weight: 700;
}

.chat-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
}

.chat-table th,
.chat-table td {
    text-align: left;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    vertical-align: top;
}

.chat-table th {
    background: var(--color-surface);
    font-weight: 700;
}

.chat-message-user .chat-message-body {
    font-weight: 600;
}

.chat-message-assistant {
    border: 1px solid var(--color-border);
    padding: 1rem;
    background: var(--color-surface);
}

.tool-call-card {
    border: 1px solid #b45309;
    padding: 0.85rem 1rem;
    margin-top: 0.75rem;
    background: var(--color-bg);
}

.tool-call-label {
    margin: 0 0 0.6rem;
    color: #b45309;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Entry-related tool calls (create/edit/delete_entry) get the same blue
   already used for the entry-ref dot elsewhere, instead of the orange
   used for task-related ones — same color coding, extended here too. */
.tool-call-card-entry {
    border-color: #1d4ed8;
}

.tool-call-card-entry .tool-call-label {
    color: #1d4ed8;
}

.tool-call-fields-table {
    margin: 0 0 0.85rem;
    font-size: 0.85rem;
}

.tool-call-actions {
    display: flex;
    gap: 0.6rem;
}

.tool-call-outcome {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tool-call-outcome-approved {
    color: #15803d;
}

.tool-call-outcome-denied {
    color: #b91c1c;
}

.tool-call-outcome-error {
    color: #b91c1c;
    text-transform: none;
    letter-spacing: normal;
}

.chat-scroll-area {
    padding-bottom: 8rem;
}

.chat-form {
    position: fixed;
    bottom: 0;
    left: 200px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    padding: 1rem 2.5rem;
    z-index: 30;
}

.chat-form textarea {
    width: 100%;
    height: 72px;
    min-height: 0;
    resize: none;
}

.chat-form-actions {
    display: flex;
    justify-content: flex-end;
}

.chat-form .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .chat-form {
        left: 0;
        padding: 0.75rem 1.25rem;
    }
}
