/* ==========================================================================
   Clearspace Internal Tool — Design System
   Brand: DM Sans, #3BABFF (blue), #323D4C (dark), #16191A (charcoal)
   ========================================================================== */

/* -- Base -- */
html {
    font-size: 15px;
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

.app-shell {
    height: calc(100vh - 3rem);
    height: calc(100dvh - 3rem);
}

main {
    -webkit-overflow-scrolling: touch;
}

.page-content {
    padding-bottom: calc(2.25rem + env(safe-area-inset-bottom));
}

.settings-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    padding: 0.875rem 0 calc(0.875rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, #f9fafb 72%, rgba(249, 250, 251, 0));
}

@media (min-width: 768px) {
    .app-shell {
        height: 100vh;
        height: 100dvh;
    }
}

/* Navigation */
.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.625rem;
    font-size: 1.0625rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.85);
    transition: all 0.15s ease;
    letter-spacing: -0.01em;
}
.nav-link:hover {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}
.nav-link.active {
    color: #fff;
    background: #3BABFF;
    font-weight: 500;
}
.nav-link.active svg {
    color: #fff;
}

/* Cards */
.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.875rem;
    padding: 1.75rem;
}
.card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 1rem;
}

/* Stat cards */
.stat-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.875rem;
    padding: 1.5rem 1.75rem;
}
.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.stat-value {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.15;
    margin-top: 0.375rem;
    letter-spacing: -0.03em;
}
.stat-sub {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.25rem;
}

/* Forms */
.form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.4rem;
    letter-spacing: -0.01em;
}
.input-field {
    display: block;
    padding: 0.5625rem 0.875rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background: #fff;
    color: #16191A;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    font-family: inherit;
    box-sizing: border-box;
}
.input-field:focus {
    outline: none;
    border-color: #3BABFF;
    box-shadow: 0 0 0 3px rgba(59, 171, 255, 0.1);
}
.input-field::placeholder {
    color: #d1d5db;
}
select.input-field {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    padding-right: 2.25rem;
    box-sizing: border-box;
    cursor: pointer;
}

/* Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #fff;
    background: #3BABFF;
    border-radius: 0.5rem;
    transition: background 0.15s ease;
    letter-spacing: -0.01em;
    font-family: inherit;
    border: none;
    cursor: pointer;
}
.btn-primary:hover { background: #2a9aee; }

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #323D4C;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    transition: background 0.15s ease;
    letter-spacing: -0.01em;
    font-family: inherit;
    cursor: pointer;
}
.btn-secondary:hover { background: #e9eaec; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: #6b7280;
    border-radius: 0.5rem;
    transition: color 0.15s ease, background 0.15s ease;
    font-family: inherit;
    border: none;
    background: none;
    cursor: pointer;
}
.btn-ghost:hover { color: #16191A; background: #f3f4f6; }

.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #F05A5A;
    background: rgba(240, 90, 90, 0.08);
    border: 1px solid rgba(240, 90, 90, 0.2);
    border-radius: 0.5rem;
    transition: background 0.15s ease;
    font-family: inherit;
    cursor: pointer;
}
.btn-danger:hover { background: rgba(240, 90, 90, 0.15); }

.btn-success {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5625rem 1.125rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #3F4D32;
    background: rgba(179, 193, 0, 0.12);
    border: 1px solid rgba(179, 193, 0, 0.25);
    border-radius: 0.5rem;
    transition: background 0.15s ease;
    font-family: inherit;
    cursor: pointer;
}
.btn-success:hover { background: rgba(179, 193, 0, 0.2); }

/* Tables */
.table-main {
    border-collapse: collapse;
}
.table-main thead {
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.table-main th {
    padding: 0.875rem 1.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}
.table-main td {
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    border-bottom: 1px solid #f3f4f6;
    color: #16191A;
}
.table-main tbody tr:last-child td {
    border-bottom: none;
}
.table-main tbody tr:hover td {
    background: #fafafa;
}

/* Status badges */
.stage-badge {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    white-space: nowrap;
    letter-spacing: -0.005em;
}
.badge-blue-light  { background: rgba(59, 171, 255, 0.1);  color: #3BABFF; }
.badge-green       { background: rgba(179, 193, 0, 0.15);  color: #3F4D32; }
.badge-gray        { background: #f3f4f6;                   color: #9ca3af; }
.badge-red         { background: rgba(240, 90, 90, 0.1);   color: #c0392b; }
.badge-amber       { background: rgba(245, 158, 11, 0.1);  color: #92400e; }

/* Detail fields */
.detail-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.3rem;
}
.detail-value {
    font-size: 0.9375rem;
    color: #16191A;
    line-height: 1.5;
}

/* Flash messages */
.flash-msg {
    animation: flashIn 0.3s ease;
}
@keyframes flashIn {
    from { opacity: 0; transform: translateY(-0.5rem); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* --- Nanobot Manager: App-specific --- */

/* Tab bar */
.tab-bar { border-bottom: 1px solid #e5e7eb; }
.tab-btn {
    padding: 0.625rem 0;
    margin-right: 1.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #9ca3af;
    border-bottom: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    cursor: pointer;
    font-family: inherit;
}
.tab-btn:hover { color: #374151; }
.tab-btn.active { color: #3BABFF; border-bottom-color: #3BABFF; }

/* Agent card hover */
.agent-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.agent-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 0.5rem;
    font-size: 14px;
    font-weight: 500;
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9999;
    font-family: 'DM Sans', sans-serif;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #f0fdf4; color: #3F4D32; border: 1px solid #bbf7d0; }
.toast.error { background: #fef2f2; color: #692729; border: 1px solid #fecaca; }

/* CodeMirror overrides — Clearspace style */
.CodeMirror {
    font-family: 'DM Sans', monospace !important;
    font-size: 13px;
    height: auto;
    min-height: 400px;
    background: #fff !important;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    color: #16191A;
}
.CodeMirror-focused {
    border-color: #3BABFF;
    box-shadow: 0 0 0 3px rgba(59, 171, 255, 0.1);
}
.CodeMirror-gutters {
    background: #f9fafb !important;
    border-right: 1px solid #e5e7eb !important;
}
.CodeMirror-linenumber { color: #9ca3af !important; }

/* Status dot pulse */
.pulse-green { animation: pulse-g 2s infinite; }
@keyframes pulse-g {
    0%, 100% { box-shadow: 0 0 0 0 rgba(179, 193, 0, 0.4); }
    50% { box-shadow: 0 0 0 5px rgba(179, 193, 0, 0); }
}

/* File sidebar active */
.file-btn.active,
.skill-btn.active,
.session-btn.active {
    background: rgba(59, 171, 255, 0.08);
    color: #3BABFF;
}

/* Logs */
.log-output {
    font-family: 'SF Mono', 'Menlo', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #374151;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1.25rem;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* --- Mobile (≤ 767px) --- */
@media (max-width: 767px) {
    /* Tabs scroll horizontally instead of wrapping. */
    .tab-bar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .tab-bar::-webkit-scrollbar { display: none; }
    .tab-btn { white-space: nowrap; margin-right: 1.25rem; }

    /* Stack any 2-col grid we use for forms. */
    .grid.grid-cols-2 { grid-template-columns: 1fr !important; }

    /* Cards: less inner padding. */
    .card { padding: 1rem; }
    .stat-card { padding: 1rem; }

    /* Bigger tap targets for nav links + tab buttons. */
    .nav-link { padding: 0.7rem 0.9rem; }
    .tab-btn { padding: 0.75rem 0; }

    /* Long monospace strings (tokens, paths) wrap instead of forcing horizontal scroll. */
    code, pre { word-break: break-word; overflow-wrap: anywhere; }

    /* Hide the live terminal pane on mobile — soft keyboard makes it unusable. */
    #terminal, #termConnectBtn { display: none !important; }
}

/* ==========================================================================
   Tiptap WYSIWYG editor
   ========================================================================== */
.tiptap-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.125rem;
    padding: 0.5rem; background: #f9fafb;
    border: 1px solid #e5e7eb; border-bottom: none; border-radius: 0.5rem 0.5rem 0 0;
}
.tiptap-toolbar button {
    min-width: 1.9rem; height: 1.9rem; padding: 0 0.45rem;
    border-radius: 0.375rem; font-size: 0.85rem; color: #16191A;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer; transition: background-color 120ms;
}
.tiptap-toolbar button:hover { background: #e5e7eb; }
.tiptap-toolbar button.is-active { background: #3BABFF; color: #fff; }
.tiptap-toolbar .sep { width: 1px; height: 1.2rem; background: #d1d5db; margin: 0 0.25rem; }

.tiptap-content {
    border: 1px solid #e5e7eb; border-radius: 0 0 0.5rem 0.5rem;
    background: #fff; padding: 1rem 1.25rem; min-height: 360px;
    font-size: 0.9rem; line-height: 1.6;
}
.tiptap-content .ProseMirror { outline: none; min-height: 320px; }
.tiptap-content h1 { font-size: 1.65rem; font-weight: 600; margin: 1rem 0 0.5rem; line-height: 1.25; }
.tiptap-content h2 { font-size: 1.35rem; font-weight: 600; margin: 0.9rem 0 0.45rem; line-height: 1.3; }
.tiptap-content h3 { font-size: 1.15rem; font-weight: 600; margin: 0.8rem 0 0.4rem; line-height: 1.35; }
.tiptap-content h4 { font-size: 1.02rem; font-weight: 600; margin: 0.7rem 0 0.35rem; }
.tiptap-content p { margin: 0.5rem 0; }
.tiptap-content ul, .tiptap-content ol { margin: 0.5rem 0; padding-left: 1.5rem; }
.tiptap-content ul { list-style: disc; }
.tiptap-content ol { list-style: decimal; }
.tiptap-content li { margin: 0.2rem 0; }
.tiptap-content li > p { margin: 0; }
.tiptap-content blockquote {
    border-left: 3px solid #d1d5db; padding-left: 0.9rem;
    margin: 0.6rem 0; color: #4b5563; font-style: italic;
}
.tiptap-content code {
    background: #f3f4f6; padding: 0.1rem 0.3rem; border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em;
}
.tiptap-content pre {
    background: #1f2937; color: #f9fafb; padding: 0.85rem 1rem;
    border-radius: 0.5rem; overflow-x: auto; margin: 0.6rem 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem;
}
.tiptap-content pre code { background: transparent; padding: 0; color: inherit; font-size: inherit; }
.tiptap-content a { color: #3BABFF; text-decoration: underline; }
.tiptap-content hr { border: none; border-top: 1px solid #e5e7eb; margin: 1rem 0; }
.tiptap-content strong { font-weight: 600; }
.tiptap-content em { font-style: italic; }

/* ==========================================================================
   File tree (Notion-style collapsible folders)
   ========================================================================== */
.file-tree { display: flex; flex-direction: column; gap: 0.05rem; }
.ft-row {
    display: flex; align-items: center; gap: 0.4rem;
    width: 100%; text-align: left; padding: 0.35rem 0.5rem;
    font-size: 0.83rem; color: #6b7280;
    background: transparent; border: none; border-radius: 0.375rem;
    cursor: pointer; transition: background-color 100ms, color 100ms;
    line-height: 1.3;
}
.ft-row:hover { background: #f3f4f6; color: #16191A; }
.ft-row.is-active, .file-btn.active { background: #eef6ff; color: #3BABFF; }
.ft-chevron {
    width: 0.8rem; height: 0.8rem; flex-shrink: 0;
    transform: rotate(0deg); transition: transform 120ms; opacity: 0.6;
}
.ft-dir-header.is-open .ft-chevron { transform: rotate(90deg); }
.ft-dir-header { font-weight: 500; color: #4b5563; }
.ft-file { color: #6b7280; }
.ft-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ft-children { display: flex; flex-direction: column; gap: 0.05rem; }
