/* UDaily BozApp Styles */

/* Main layout — horizontal top nav.
   Fixed to the viewport so the body never scrolls; each page owns its own scroll
   region (the chat page scrolls its message list, other pages scroll main-content). */
.main-layout {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.top-nav {
    background-color: #2c3e50;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.top-nav .brand {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
    text-decoration: none;
}

.top-nav .nav-links {
    display: none;
    gap: 0.5rem;
    align-items: center;
}

.top-nav .nav-links a {
    color: #ecf0f1;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.top-nav .nav-links a:hover,
.top-nav .nav-links a.active {
    background-color: rgba(255, 255, 255, 0.15);
}

.top-nav .nav-links.nav-open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: #2c3e50;
    padding: 1rem;
    z-index: 100;
}

.nav-user {
    color: #ecf0f1;
    font-size: 0.875rem;
    margin-left: auto;
}

.nav-logout {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ecf0f1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.nav-logout:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Hamburger — visible by default (mobile-first) */
.hamburger-btn {
    display: block;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* Desktop nav */
@media (min-width: 768px) {
    .hamburger-btn {
        display: none;
    }
    .top-nav .nav-links {
        display: flex !important;
        flex-direction: row;
        position: static;
        padding: 0;
    }
}

.main-content {
    flex: 1;
    /* min-height:0 lets this flex item shrink below its content so overflow-y can
       take effect; tall content pages scroll here rather than growing the body. */
    min-height: 0;
    overflow-y: auto;
    /* Mobile-first: tight horizontal insets so the chat gets the full width.
       Desktop padding is restored at the 640px breakpoint below. */
    padding: 0.75rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.footer {
    text-align: center;
    padding: 1rem;
    color: #6c757d;
    font-size: 0.875rem;
    border-top: 1px solid #dee2e6;
}

/* Chat layout — fills the available height of main-content so only the message
   list scrolls, leaving the thread selector and input pinned. */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-messages-readonly {
    padding: 1rem 0;
}

.chat-input-area {
    padding: 0.75rem 0.75rem 1rem;
    border-top: 1px solid #e0e0e0;
}

/* Message bubbles */
.message {
    margin-bottom: 1rem;
    max-width: 80%;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-client {
    margin-left: auto;
    background: #e3f2fd;
    border-radius: 12px 12px 0 12px;
    padding: 0.75rem 1rem;
}

.message-boz {
    margin-right: auto;
    background: #f5f5f5;
    border-radius: 12px 12px 12px 0;
    padding: 0.75rem 1rem;
    /* Boz messages render markdown as HTML, so let the block elements control spacing
       rather than preserving raw newlines. */
    white-space: normal;
}

/* Rendered markdown inside a Boz bubble: tighten default block spacing so the bubble
   reads as a single message rather than a page of stacked blocks. */
.message-boz > :first-child {
    margin-top: 0;
}

.message-boz > :last-child {
    margin-bottom: 0;
}

.message-boz p {
    margin: 0 0 0.5rem 0;
}

.message-boz ul,
.message-boz ol {
    margin: 0 0 0.5rem 0;
    padding-left: 1.5rem;
}

.message-boz li {
    margin-bottom: 0.25rem;
}

.message-boz pre {
    background: #ececec;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
}

.message-boz code {
    background: #ececec;
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
    font-size: 0.9em;
}

.message-boz pre code {
    background: none;
    padding: 0;
}

/* Feedback control */
.feedback-control {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0.15rem 0 0.5rem 0;
}

.feedback-thumb {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}

.feedback-thumb:hover:not(:disabled) {
    opacity: 1;
    background: #f0f0f0;
}

.feedback-thumb.active {
    opacity: 1;
    background: #e3f2fd;
    border-color: #90caf9;
}

.feedback-thumb:disabled {
    cursor: default;
}

.feedback-status {
    font-size: 0.8rem;
    color: #4caf50;
    margin-left: 0.25rem;
}

.feedback-error {
    font-size: 0.8rem;
    color: #c62828;
    margin-left: 0.25rem;
}

.feedback-comment {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin: 0 0 0.75rem 0;
    max-width: 75%;
}

.feedback-comment-input {
    flex: 1;
    font-size: 0.85rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    resize: vertical;
}

.feedback-comment-submit {
    background: #1976d2;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
}

.feedback-comment-submit:disabled {
    opacity: 0.6;
    cursor: default;
}

/* Tool activity — debug-only live status. Reads as developer output (muted monospace) rather than a
   client-facing success cue, since ordinary clients never see this block. */
.tool-activities {
    margin-bottom: 0.5rem;
}

.tool-activity {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8rem;
    color: #888;
    padding: 0.2rem 0;
}

.tool-activity-complete {
    color: #555;
}

/* Debug toggle — shown only to Admins (gated by AuthorizeView) */
.debug-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    color: #6c757d;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    white-space: nowrap;
}

.debug-toggle input {
    cursor: pointer;
    margin: 0;
}

/* Backstage bubble — persistent, per-turn developer record of Boz's reasoning and Giles commands.
   Visually secondary and clearly "developer": dashed border, muted panel, monospace commands. */
.backstage-bubble {
    margin: 0 auto 1rem 0;
    max-width: 80%;
    border: 1px dashed #b0bec5;
    border-radius: 8px;
    background: #fafafa;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
}

.backstage-label {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.68rem;
    font-weight: 600;
    color: #90a4ae;
    margin-bottom: 0.35rem;
}

.backstage-reasoning {
    color: #607d8b;
    font-style: italic;
    white-space: pre-wrap;
    margin-bottom: 0.35rem;
}

.backstage-tool {
    margin-bottom: 0.15rem;
}

.backstage-tool code {
    display: block;
    background: #eceff1;
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.8rem;
    color: #37474f;
    white-space: pre-wrap;
    word-break: break-word;
}

.backstage-tool-result {
    color: #78909c;
    font-size: 0.78rem;
    margin: 0 0 0.5rem 0.25rem;
}

/* Streaming caret — blinks at the tail of in-progress Boz text. */
.streaming-caret {
    opacity: 0.7;
    animation: caret-blink 1s steps(2, start) infinite;
}

@keyframes caret-blink {
    50% {
        opacity: 0;
    }
}

/* Thinking indicator — texting-style bouncing dots in a Boz bubble, paired with a
   rotating status phrase so long tool-use turns still read as live. */
.thinking-bubble {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #90a4ae;
    animation: typing-bounce 1.2s ease-in-out infinite;
}

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

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

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.thinking-phrase {
    color: #78909c;
    font-style: italic;
    font-size: 0.9rem;
    animation: phrase-fade-in 0.4s ease;
}

@keyframes phrase-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Respect reduced-motion preferences: the indicator falls back to static dots + phrase. */
@media (prefers-reduced-motion: reduce) {
    .typing-dots span,
    .thinking-phrase,
    .streaming-caret {
        animation: none;
    }
}

/* Thread selector */
.thread-selector {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e0e0e0;
}

/* Input area */
.chat-input {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 0.75rem;
    resize: none;
    font-family: inherit;
    /* Auto-grow: JS sets height to fit content; min/max keep it bounded and
       overflow-y kicks in a scrollbar once the max is reached. box-sizing keeps
       the scrollHeight measurement accurate against the padded box. */
    box-sizing: border-box;
    min-height: 3.5rem;
    max-height: 12rem;
    overflow-y: auto;
    line-height: 1.4;
}

.chat-send-btn {
    /* Compact, fixed-width button so the textarea gets the horizontal room. It
       still stretches to the input's height via the flex row's default
       align-items: stretch, matching the "as tall but not as wide" goal. */
    flex: 0 0 auto;
    width: 4rem;
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 600;
}

.chat-send-btn:not(:disabled):hover {
    background: #1f2d3a;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Library */
.library-controls {
    margin-bottom: 1rem;
}

.entity-type-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.entity-grid {
    display: grid;
    gap: 0.75rem;
}

.entity-card {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.15s;
}

.entity-card:hover {
    background-color: #f8f9fa;
}

.entity-type-badge {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    background: #e9ecef;
    color: #495057;
    text-transform: capitalize;
}

.entity-name {
    font-weight: 500;
}

@media (min-width: 640px) {
    .main-content {
        padding: 1.5rem;
    }
    .entity-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 900px) {
    .entity-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Story content — entity references and typed values */
.story-entity-ref {
    color: #2c3e50;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.story-entity-ref:hover {
    color: #1a252f;
}

.story-typed-value {
    font-weight: 500;
}

.story-typed-value.typed-date {
    color: #6c757d;
}

.story-typed-value.typed-num {
    color: #495057;
}

.story-typed-value.typed-dur {
    color: #6c757d;
    font-style: italic;
}
