/* ============================================================
   TiltedPortal — Brand Theme (dark chrome + light content)
   Tokens mirror tiltedllc.com; layout favors readability for
   long-form ticket content on a near-white surface.
   ============================================================ */

:root {
    /* Brand palette (from tiltedllc.com) */
    --navy: #1A1A2E;
    --navy-mid: #20203A;
    --navy-light: #2A2A45;
    --orange: #ED5C39;
    --orange-hover: #d44a29;
    --orange-dim: rgba(237, 92, 57, 0.12);

    /* Light-content tokens */
    --bg: #F7F7F8;
    --surface: #FFFFFF;
    --surface-alt: #FAFAFB;
    --border: #E5E5EA;
    --border-strong: #D1D1D8;
    --text: #1A1A2E;
    --text-muted: #5A5A7A;
    --text-soft: #8888AA;

    /* Chrome-on-dark text */
    --on-navy: #FFFFFF;
    --on-navy-muted: #8888AA;

    /* Typography */
    --font-display: 'DM Sans', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

    --radius: 4px;
    --radius-sharp: 2px;
    --shadow-sm: 0 1px 2px rgba(26, 26, 46, 0.04);
    --shadow: 0 1px 3px rgba(26, 26, 46, 0.06), 0 4px 16px rgba(26, 26, 46, 0.04);

    /* Bootstrap CSS-var overrides where 5.1 honors them */
    --bs-body-font-family: var(--font-body);
    --bs-body-color: var(--text);
    --bs-body-bg: var(--bg);
    --bs-link-color: var(--orange);
    --bs-link-hover-color: var(--orange-hover);
    --bs-border-color: var(--border);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.65;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
}

h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.15; }
h2 { font-size: clamp(22px, 3vw, 30px); }
h3 { font-size: 20px; }
h4 { font-size: 16px; }

a { color: var(--orange); text-decoration: none; }
a:hover { color: var(--orange-hover); text-decoration: underline; }

.font-mono { font-family: var(--font-mono); }

/* Section labels with // prefix (brand signature) */
.section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--orange);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.section-label::before {
    content: '//';
    opacity: 0.5;
    font-family: var(--font-mono);
}

/* ── Brand mark (used in navbar + footer) ── */
.brand-mark {
    font-family: var(--font-mono);
    font-weight: 800;
    letter-spacing: -0.02em;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.brand-mark:hover { text-decoration: none; }
.brand-mark .ch { color: var(--orange); }
.brand-mark .ds { color: var(--on-navy-muted); }
.brand-mark .nm { color: var(--on-navy); }
.brand-mark .cur {
    display: inline-block;
    width: 0.5em;
    height: 0.8em;
    background: var(--orange);
    vertical-align: middle;
    margin-left: 0.12em;
    position: relative;
    top: -0.05em;
    animation: blink 1.1s step-end infinite;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ── Navbar (dark chrome) ── */
.tp-navbar {
    background: var(--navy) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 14px 0;
}
.tp-navbar .navbar-brand {
    font-size: 24px;
    color: var(--on-navy) !important;
}
.tp-navbar .navbar-brand:hover { color: var(--on-navy) !important; }
.tp-navbar .navbar-nav .nav-link {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--on-navy-muted) !important;
    padding: 6px 16px !important;
    transition: color 0.2s;
}
.tp-navbar .navbar-nav .nav-link:hover,
.tp-navbar .navbar-nav .nav-link.active {
    color: var(--orange) !important;
}
.tp-navbar .navbar-toggler {
    border-color: rgba(237, 92, 57, 0.3);
}
.tp-navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28237, 92, 57, 0.8%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* ── Sidebar (dark chrome) — utility class for future left/right rails ── */
.tp-sidebar {
    background: var(--navy);
    color: var(--on-navy);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    min-height: 100%;
    padding: 20px 0;
}
.tp-sidebar .nav-link {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--on-navy-muted);
    padding: 10px 20px;
    border-left: 2px solid transparent;
}
.tp-sidebar .nav-link:hover { color: var(--on-navy); }
.tp-sidebar .nav-link.active {
    color: var(--orange);
    border-left-color: var(--orange);
    background: rgba(237, 92, 57, 0.06);
}

/* ── Buttons ── */
.btn {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: var(--radius-sharp);
    padding: 10px 24px;
    transition: opacity 0.2s, transform 0.2s, color 0.2s, background 0.2s, border-color 0.2s;
}
.btn-primary {
    background: var(--orange);
    border-color: var(--orange);
    color: var(--navy);
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-primary.active {
    background: var(--orange-hover);
    border-color: var(--orange-hover);
    color: var(--navy);
    transform: translateY(-1px);
}
.btn-outline-primary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-strong);
}
.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
    background: var(--text);
    color: var(--surface);
    border-color: var(--text);
}
.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn-secondary:hover,
.btn-secondary:focus,
.btn-secondary:active {
    background: var(--surface-alt);
    border-color: var(--orange);
    color: var(--text);
}
.btn-link {
    color: var(--orange);
    text-decoration: none;
    padding: 0;
    letter-spacing: normal;
    text-transform: none;
    font-family: var(--font-body);
    font-weight: 500;
}
.btn-link:hover { color: var(--orange-hover); text-decoration: underline; }

.btn:focus,
.btn:active:focus {
    box-shadow: 0 0 0 2px rgba(237, 92, 57, 0.25);
}

/* ── Forms (light theme on content surface) ── */
.form-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-control,
.form-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sharp);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 10px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-control:focus,
.form-select:focus {
    background: var(--surface);
    color: var(--text);
    border-color: var(--orange);
    box-shadow: 0 0 0 2px rgba(237, 92, 57, 0.15);
    outline: none;
}
.form-control::placeholder { color: var(--text-soft); }
textarea.form-control { resize: vertical; min-height: 120px; }

/* ── Cards (light surface, brand-edged) ── */
.card,
.tp-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--text);
}
.card-header,
.card-footer {
    background: var(--surface-alt);
    border-color: var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.card-body { color: var(--text); }

/* ── Tables (light) ── */
.table {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
    margin-bottom: 0;
}
.table > :not(caption) > * > * {
    background-color: var(--bs-table-bg, transparent);
    border-bottom-color: var(--border);
    color: inherit;
    padding: 12px 14px;
}
.table thead th {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border-strong);
}
.table-hover tbody tr:hover { background: var(--surface-alt); }

/* ── Footer (dark chrome) ── */
.tp-footer {
    background: var(--navy);
    color: var(--on-navy-muted);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 32px 0 40px;
    margin-top: auto;
}
.tp-footer .footer-mark {
    font-family: var(--font-mono);
    font-weight: 800;
    font-size: 22px;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 6px;
}
.tp-footer .footer-tagline {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--on-navy-muted);
    letter-spacing: 0.08em;
}
.tp-footer .footer-meta {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--on-navy-muted);
    line-height: 2;
}
.tp-footer a {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--on-navy-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.tp-footer a:hover { color: var(--orange); text-decoration: none; }

/* ── Dropdown menus (theme to match content surface) ── */
.dropdown-menu {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px 0;
    min-width: 200px;
}
.dropdown-item {
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    padding: 8px 16px;
}
.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--surface-alt);
    color: var(--orange);
}
.dropdown-item form {
    margin: 0;
}
.dropdown-item button.dropdown-item {
    width: 100%;
    text-align: left;
    border: 0;
    background: none;
}
.dropdown-divider {
    border-color: var(--border);
    margin: 6px 0;
}
.tp-navbar .nav-link.dropdown-toggle::after {
    margin-left: 0.4em;
    vertical-align: 0.15em;
}

/* ── Mega menu ── */
.tp-mega {
    min-width: 280px;
    padding: 12px 8px;
    border-top: 2px solid var(--orange);
    display: none;
    flex-direction: row;
    gap: 0;
}
.tp-mega.show { display: flex !important; }
.tp-mega-col {
    flex: 1;
    min-width: 140px;
    padding: 0 8px;
}
.tp-mega-col + .tp-mega-col {
    border-left: 1px solid var(--border);
}
.tp-mega-heading {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--orange);
    padding: 0 8px 8px;
    margin-bottom: 4px;
}
.tp-mega .dropdown-item {
    display: flex;
    align-items: center;
    font-size: 13px;
    padding: 7px 8px;
    border-radius: var(--radius-sharp);
    gap: 8px;
}
.tp-mega .dropdown-item i {
    font-size: 14px;
    color: var(--text-soft);
    flex-shrink: 0;
}
.tp-mega .dropdown-item:hover i { color: var(--orange); }

@media (max-width: 767.98px) {
    .tp-mega {
        flex-direction: column;
        min-width: 0;
        width: 100%;
        border-top: none;
        border-left: 2px solid var(--orange);
        padding: 4px 0 4px 4px;
        box-shadow: none;
    }
    .tp-mega-col {
        min-width: 0;
    }
    .tp-mega-col + .tp-mega-col {
        border-left: none;
        border-top: 1px solid var(--border);
        padding-top: 8px;
        margin-top: 4px;
    }
}

/* ── Status pill (ticket states, env labels, health badges) ── */
.tp-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.tp-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.tp-status.ok { color: #16a34a; }
.tp-status.warn { color: #d97706; }
.tp-status.err { color: #dc2626; }
.tp-status.info { color: var(--orange); }

/* ── CodeMirror HTML editor ── */
.CodeMirror {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    border: 1px solid var(--border);
    border-radius: var(--radius-sharp);
    background: var(--surface);
    color: var(--text);
    height: auto;
}
.CodeMirror-scroll { background: var(--surface); }
.CodeMirror-gutters {
    background: var(--surface-alt);
    border-right: 1px solid var(--border);
}
.CodeMirror-linenumber { color: var(--text-soft); }
.CodeMirror-cursor { border-left-color: var(--orange); }
.CodeMirror-focused .CodeMirror-gutters { border-right-color: var(--border-strong); }
.CodeMirror-selected { background: rgba(237,92,57,0.12) !important; }

/* ── Modals ── */
.modal-header {
    background: var(--navy);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding: 14px 20px;
}
.modal-title {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--on-navy);
}
.modal-header .btn-close {
    filter: invert(1) opacity(0.5);
}
.modal-header .btn-close:hover { filter: invert(1) opacity(1); }
.modal-content {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(26,26,46,0.18);
}
.modal-body {
    background: var(--bg);
    padding: 24px;
}

/* ── Scrollbar (subtle) ── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

/* ── Ticket comment thread ── */
.comment-block {
    padding: 14px 16px;
    border-left: 3px solid var(--border);
    background: var(--surface);
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 12px;
}
.comment-block.comment-internal {
    border-left-color: #d97706;
    background: #fffbeb;
}
.comment-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.comment-author {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.04em;
}
.comment-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-soft);
}
.comment-body {
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
}
.comment-body-plain {
    white-space: pre-wrap;
}
/* Quill-rendered HTML resets */
.comment-body p { margin: 0 0 .4em; }
.comment-body ul, .comment-body ol { margin: 0 0 .4em; padding-left: 1.4em; }
.comment-body blockquote { margin: 0 0 .4em 0; padding: 4px 10px; border-left: 3px solid var(--border-strong); color: var(--text-muted); }
.comment-body code { font-family: var(--font-mono); font-size: .875em; background: var(--bg); padding: 1px 4px; border-radius: 3px; }
.comment-body pre { background: var(--bg); padding: 10px 12px; border-radius: 4px; font-family: var(--font-mono); font-size: .8em; overflow-x: auto; }

/* Quill editor overrides */
#comment-editor .ql-editor,
#description-editor .ql-editor { font-family: var(--font-body); font-size: 14px; color: var(--text); }
#comment-editor .ql-editor { min-height: 90px; }
#description-editor .ql-editor { min-height: 140px; }
#comment-editor .ql-toolbar,
#description-editor .ql-toolbar { border-color: var(--border); border-radius: 6px 6px 0 0; background: var(--surface-alt); }
#comment-editor .ql-container,
#description-editor .ql-container { border-color: var(--border); border-radius: 0 0 6px 6px; }
#comment-editor,
#description-editor { border: none !important; }

/* ── Ticket detail sidebar rows ── */
.tp-detail-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.tp-detail-row:last-child { border-bottom: 0; padding-bottom: 0; }
.tp-detail-row:first-child { padding-top: 0; }
.tp-detail-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-soft);
}
.tp-detail-val {
    font-size: 13px;
    color: var(--text);
}

/* ── Icon action buttons (table rows, inline actions) ── */
.tp-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sharp);
    background: transparent;
    padding: 0;
    cursor: pointer;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s, background 0.15s;
    font-size: 14px;
}
.tp-icon-btn:hover {
    color: var(--orange);
    background: var(--orange-dim);
    text-decoration: none;
}

/* ── Loading overlay ── */
#tp-loading {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 26, 46, 0.45);
    z-index: 9990;
    align-items: center;
    justify-content: center;
}
#tp-loading.is-active { display: flex; }
.tp-loading-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 28px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}
.tp-loading-card span {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.tp-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--orange);
    border-radius: 50%;
    flex-shrink: 0;
    animation: tp-spin 0.65s linear infinite;
}
@keyframes tp-spin { to { transform: rotate(360deg); } }

/* ── Refresh button spin state ── */
.tp-btn-spin i { display: inline-block; animation: tp-spin 0.65s linear infinite; }

/* ── Toast notifications ── */
#tp-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9995;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 380px;
}
.tp-toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.05em;
    color: var(--text);
    pointer-events: all;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.tp-toast.tp-toast-enter {
    opacity: 0;
    transform: translateX(16px);
}
.tp-toast.tp-toast-fade {
    opacity: 0;
    transform: translateX(16px);
}
.tp-toast.tp-toast-success { border-left-color: #16a34a; }
.tp-toast.tp-toast-error   { border-left-color: #dc2626; }
