:root {
    --navy: #081729;
    --blue: #163b57;
    --blue-hover: #0f3049;
    --yellow: #c7a35a;
    --yellow-soft: #f2e7ce;
    --canvas: #f4efe5;
    --surface: #fffdf8;
    --text: #142234;
    --muted: #5f6974;
    --border: #d9d0c1;
    --success: #176b55;
    --success-soft: #dceee7;
    --danger: #9b443f;
    --danger-soft: #f3dfdc;
    --warning: #80601f;
    --warning-soft: #f2e7ce;
    --radius: 3px;
    --shadow: 0 18px 45px rgba(8, 23, 41, 0.08);
}

* { box-sizing: border-box; }
html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    margin: 0;
    background: var(--canvas);
    color: var(--text);
    font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    width: 100%;
}

button, input, select, textarea { font: inherit; }

.app-header {
    background: var(--navy);
    color: #fff;
    border-bottom: 1px solid rgba(199, 163, 90, 0.3);
}

.header-inner {
    width: min(100% - 48px, 1180px);
    min-height: 82px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0;
    color: #fff;
    text-decoration: none;
    width: 220px;
    height: 64px;
}

.brand-mark { display: none; }
.brand > span:last-child {
    display: block;
    width: 220px;
    height: 64px;
    overflow: hidden;
    background: url('/webapp/assets/inception-logo-horizontal-transparent.webp?v=3') center / contain no-repeat;
    color: transparent;
    font-size: 0;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 24px;
    font-size: 0.92rem;
}

.main-nav a {
    color: #d8dee4;
    text-decoration: none;
    transition: color 0.15s ease;
}

.main-nav a:hover { color: #fff; }
.main-nav .active {
    color: var(--yellow);
    font-weight: 700;
}

.language-switcher {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-left: auto;
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.78rem;
}

.language-switcher a {
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
}

.language-switcher a:hover,
.language-switcher a:focus-visible {
    color: #fff;
}

.language-switcher strong {
    color: #fff;
    font-weight: 800;
}

.app-main {
    width: min(100% - 48px, 1180px);
    margin: 48px auto 84px;
    flex: 1;
}

.intro {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 36px;
    margin-bottom: 28px;
}

.eyebrow {
    color: var(--warning);
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 6px;
}

#page-title, h1 {
    margin: 0 0 10px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 600;
    line-height: 1.08;
    letter-spacing: -0.035em;
    color: var(--navy);
}

.intro p {
    margin: 0;
    color: var(--muted);
    max-width: 700px;
    font-size: 1.08rem;
}

.privacy-note {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    max-width: 320px;
}

.privacy-note strong {
    display: block;
    font-size: 13px;
    color: var(--navy);
    margin-bottom: 4px;
}

.privacy-note span {
    font-size: 12px;
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.panel-heading h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--navy);
    display: inline;
}

.step {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--navy);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    margin-right: 8px;
    vertical-align: middle;
}

.badge-status {
    background: var(--yellow-soft);
    color: var(--warning);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
}

.badge-verified {
    background: var(--success-soft);
    color: var(--success);
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--navy);
}

.required { color: var(--danger); }

.field-group input,
.field-group select,
.field-group textarea {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(22, 59, 87, 0.12);
}

.hint {
    font-size: 12px;
    color: var(--muted);
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

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

.btn-primary {
    background: var(--blue);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--blue-hover);
}

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-outline {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.btn-outline:hover {
    color: var(--danger);
    border-color: var(--danger);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 8px;
}

.btn-close:hover { color: var(--navy); }

.feedback-msg {
    margin-top: 14px;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: var(--radius);
    display: none;
}

.feedback-msg.show { display: block; }
.feedback-msg.success { background: var(--success-soft); color: var(--success); }
.feedback-msg.error { background: var(--danger-soft); color: var(--danger); }
.feedback-msg.warning { background: var(--warning-soft); color: var(--warning); }

/* OTP section */
.otp-input-wrap {
    display: flex;
    justify-content: center;
    margin: 20px 0 10px;
}

#otp-code-input {
    width: 240px;
    font-family: monospace;
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 8px;
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

#otp-code-input:focus {
    border-color: var(--blue);
    outline: none;
    box-shadow: 0 0 0 4px rgba(22, 59, 87, 0.12);
}

.text-center { text-align: center; display: block; }

/* Support Hub & Chat */
.hub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.user-greeting {
    display: flex;
    align-items: center;
    gap: 12px;
}

.welcome-text {
    font-size: 14px;
    color: var(--navy);
}

.hub-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hub-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    min-height: 540px;
}

.hub-sidebar {
    border-right: 1px solid var(--border);
    padding-right: 20px;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--navy);
}

.count-badge {
    background: #e2e8f0;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

.tickets-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 520px;
}

.ticket-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.ticket-card:hover {
    border-color: var(--blue);
    background: #fafcfe;
}

.ticket-card.active {
    border-color: var(--blue);
    border-left: 4px solid var(--blue);
    background: #f1f5f9;
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.card-ticket-id {
    font-family: monospace;
    font-size: 12px;
    font-weight: 700;
    color: var(--blue);
}

.card-status {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.status-open { background: #dbeafe; color: #1e40af; }
.status-in_progress { background: var(--yellow-soft); color: var(--warning); }
.status-resolved { background: var(--success-soft); color: var(--success); }
.status-closed { background: #e2e8f0; color: #475569; }

.card-subject {
    font-size: 14px;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-snippet {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-date {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 6px;
    text-align: right;
}

.hub-main {
    display: flex;
    flex-direction: column;
}

.chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    text-align: center;
    color: var(--muted);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
}

.placeholder-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.chat-placeholder h3 {
    margin: 0 0 6px;
    color: var(--navy);
    font-size: 18px;
}

.chat-placeholder p {
    margin: 0 0 20px;
    max-width: 360px;
    font-size: 14px;
}

.new-ticket-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.panel-inner-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.panel-inner-head h3 {
    margin: 0;
    font-size: 16px;
    color: var(--navy);
}

.mt-3 { margin-top: 16px; }

/* Conversation stream */
.chat-conversation-panel {
    display: flex;
    flex-direction: column;
    height: 560px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.chat-topbar {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.ticket-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.ticket-id {
    font-family: monospace;
    font-weight: 700;
    color: var(--blue);
    margin-right: 8px;
}

.ticket-subject {
    font-weight: 600;
    color: var(--navy);
    font-size: 15px;
}

.ticket-category-tag {
    font-size: 11px;
    background: #e2e8f0;
    padding: 3px 8px;
    border-radius: 10px;
    color: var(--text);
    margin-left: 6px;
}

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #fafcfe;
}

.chat-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.bubble-user {
    align-self: flex-end;
}

.bubble-user .bubble-body {
    background: var(--blue);
    color: #fff;
    border-radius: 12px 12px 2px 12px;
}

.bubble-admin {
    align-self: flex-start;
}

.bubble-admin .bubble-body {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 2px;
}

.bubble-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 11px;
}

.bubble-author {
    font-weight: 700;
}

.bubble-user .bubble-author { color: var(--blue); text-align: right; }
.bubble-admin .bubble-author { color: #0284c7; }

.bubble-system {
    align-self: center;
    max-width: 90%;
}

.bubble-system-body {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 12.5px;
    line-height: 1.45;
    text-align: center;
    word-break: break-word;
}

.bubble-system-body .bubble-time {
    display: block;
    margin-top: 3px;
}

.bubble-time {
    color: #94a3b8;
    font-size: 10px;
}

.bubble-body {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chat-reply-bar {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #fff;
}

.chat-reply-bar form {
    display: flex;
    gap: 12px;
}

.chat-reply-bar textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-size: 14px;
}

.chat-reply-bar textarea:focus {
    outline: none;
    border-color: var(--blue);
}

.hidden { display: none !important; }

/* Back button in chat topbar (desktop: hidden, mobile: flex) */
.btn-back-tickets {
    display: none;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--blue);
    cursor: pointer;
    margin-bottom: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    transition: all 0.15s ease;
}

.btn-back-tickets:hover {
    background: #f1f5f9;
    border-color: var(--blue);
}

/* Footer */
.app-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    margin-top: auto;
    padding: 24px 0;
    color: var(--muted);
    font-size: 13px;
}

.footer-inner {
    width: min(100% - 48px, 1180px);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-inner p { margin: 0; }
.footer-links { display: flex; gap: 8px; }
.footer-links a { color: var(--muted); text-decoration: none; }
.footer-links a:hover { color: var(--navy); }

/* ==========================================================================
   Responsive & Mobile Adaptations (Tablets and Phones)
   ========================================================================== */

@media (max-width: 768px) {
    /* Header */
    .header-inner {
        min-height: auto;
        padding: 12px 0;
        flex-wrap: wrap;
        gap: 12px 16px;
        justify-content: space-between;
        width: min(100% - 32px, 1180px);
    }
    .brand, .brand > span:last-child {
        width: 160px;
        height: 48px;
    }
    .language-switcher {
        order: 2;
        margin-left: auto;
    }
    .main-nav {
        order: 3;
        width: 100%;
        gap: 18px;
        padding-top: 10px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        font-size: 0.9rem;
    }

    /* Main Container & Intro */
    .app-main {
        width: min(100% - 32px, 1180px);
        margin: 24px auto 48px;
    }
    .intro {
        flex-direction: column;
        gap: 12px;
        margin-bottom: 20px;
    }
    #page-title, h1 {
        font-size: clamp(1.65rem, 5.5vw, 2.2rem);
        line-height: 1.15;
    }
    .intro p {
        font-size: 0.95rem;
    }
    /* When active inside the support hub on mobile, hide the bulky intro */
    body.hub-active .intro {
        display: none;
    }

    /* Panels & Headings */
    .panel {
        padding: 20px 16px;
        margin-bottom: 20px;
    }
    .panel-heading {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 18px;
        padding-bottom: 14px;
    }
    .panel-heading h2 {
        font-size: 1.15rem;
        line-height: 1.3;
    }

    /* Forms & Inputs */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .field-group input,
    .field-group select,
    .field-group textarea {
        font-size: 16px; /* Crucial for iOS Safari not to zoom in */
        padding: 12px 14px;
        width: 100%;
    }
    .form-actions {
        flex-direction: column;
        width: 100%;
        gap: 10px;
        margin-top: 20px;
    }
    .form-actions .btn {
        width: 100%;
        min-height: 46px;
        font-size: 15px;
    }

    /* Step 2 (OTP code) */
    .otp-input-wrap {
        margin: 16px 0 10px;
    }
    #otp-code-input {
        max-width: 100%;
        width: 220px;
        font-size: 28px;
        letter-spacing: 6px;
        padding: 8px 10px;
    }
    .section-description {
        word-break: break-word;
        text-align: center;
        font-size: 14px;
    }

    /* Step 3 (Support Hub) */
    .hub-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        padding-bottom: 16px;
        margin-bottom: 18px;
    }
    .user-greeting {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        width: 100%;
    }
    .welcome-text {
        font-size: 13px;
        word-break: break-word;
    }
    .hub-actions {
        width: 100%;
        display: flex;
        gap: 10px;
    }
    .hub-actions .btn {
        flex: 1;
        min-height: 42px;
        font-size: 13px;
    }

    /* Master-Detail Navigation on Mobile */
    .hub-layout {
        display: block;
        min-height: auto;
    }
    .hub-sidebar {
        border-right: none;
        border-bottom: none;
        padding-right: 0;
        padding-bottom: 0;
        max-height: none;
        width: 100%;
    }
    .tickets-list {
        max-height: none;
        gap: 10px;
    }
    .ticket-card {
        padding: 14px 12px;
    }
    .ticket-card:active {
        background: #e2e8f0;
    }

    /* In mobile list view: hide chat/new panel, show sidebar */
    .hub-layout:not(.mobile-chat-open):not(.mobile-new-open) .hub-main {
        display: none;
    }
    .hub-layout.has-no-tickets:not(.mobile-chat-open):not(.mobile-new-open) .hub-main {
        display: block;
        margin-top: 14px;
    }

    /* When conversation is open on mobile: hide sidebar, show chat */
    .hub-layout.mobile-chat-open .hub-sidebar {
        display: none;
    }
    .hub-layout.mobile-chat-open .hub-main {
        display: block;
        width: 100%;
    }
    .btn-back-tickets {
        display: inline-flex;
    }

    /* When new ticket is open on mobile: hide sidebar, show form */
    .hub-layout.mobile-new-open .hub-sidebar {
        display: none;
    }
    .hub-layout.mobile-new-open .hub-main {
        display: block;
        width: 100%;
    }

    /* Chat Conversation Panel on Mobile */
    .chat-conversation-panel {
        height: 68vh;
        min-height: 480px;
        max-height: 700px;
    }
    .chat-topbar {
        padding: 10px 12px;
    }
    .ticket-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        width: 100%;
    }
    .ticket-title-wrap {
        display: flex;
        align-items: baseline;
        gap: 8px;
        flex-wrap: wrap;
    }
    .ticket-id {
        font-size: 13px;
    }
    .ticket-subject {
        font-size: 14px;
        line-height: 1.35;
        word-break: break-word;
    }
    .ticket-status-wrap {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: wrap;
    }
    .chat-messages-container {
        padding: 12px 10px;
        gap: 12px;
        -webkit-overflow-scrolling: touch;
    }
    .chat-bubble-wrap {
        max-width: 88%;
    }
    .bubble-body {
        padding: 10px 13px;
        font-size: 13.5px;
    }
    .chat-reply-bar {
        padding: 8px 10px;
    }
    .chat-reply-bar form {
        display: flex;
        gap: 8px;
        align-items: flex-end;
    }
    .chat-reply-bar textarea {
        font-size: 15px;
        padding: 8px 10px;
        min-height: 44px;
    }
    #btn-send-reply {
        padding: 0 16px;
        height: 44px;
        font-size: 14px;
        flex-shrink: 0;
    }

    /* New Ticket Panel on Mobile */
    .new-ticket-panel {
        padding: 16px 14px;
    }
    .panel-inner-head {
        margin-bottom: 16px;
        padding-bottom: 10px;
    }
    .new-ticket-panel .form-actions {
        flex-direction: column;
        gap: 10px;
    }
    .new-ticket-panel .form-actions .btn {
        width: 100%;
        min-height: 44px;
    }

    /* Footer on Mobile */
    .footer-inner {
        width: min(100% - 32px, 1180px);
        flex-direction: column;
        text-align: center;
        gap: 14px;
    }
    .footer-links {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px 14px;
    }
}

@media (max-width: 480px) {
    .header-inner,
    .app-main,
    .footer-inner {
        width: min(100% - 24px, 1180px);
    }
    .panel {
        padding: 16px 12px;
    }
    #page-title, h1 {
        font-size: 1.65rem;
    }
    #otp-code-input {
        width: 200px;
        font-size: 26px;
        letter-spacing: 5px;
    }
}
