:root {
    --brand-primary: #6c5ffc;
    --portal-bg: #f4f7fb;
    --portal-text: #172033;
    --portal-muted: #6d7788;
    --portal-border: #e5eaf1;
    --portal-sidebar: #101729;
}

* { box-sizing: border-box; }
body { color: var(--portal-text); font-family: Inter, "Segoe UI", Arial, sans-serif; }
a { text-decoration: none; }
.btn-brand { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; box-shadow: 0 8px 18px color-mix(in srgb, var(--brand-primary) 22%, transparent); }
.btn-brand:hover, .btn-brand:focus { background: color-mix(in srgb, var(--brand-primary) 88%, #000); border-color: color-mix(in srgb, var(--brand-primary) 88%, #000); color: #fff; }

.portal-guest { min-height: 100vh; margin: 0; display: grid; place-items: center; padding: 32px 18px; background: radial-gradient(circle at 15% 15%, color-mix(in srgb, var(--brand-primary) 22%, transparent), transparent 32%), linear-gradient(145deg, #0d1425, #18213a 52%, #101729); }
.portal-guest main { width: min(100%, 480px); text-align: center; }
.guest-brand-logo { max-width: min(100%, 310px); max-height: 112px; object-fit: contain; margin: 0 auto 24px; filter: drop-shadow(0 8px 18px rgba(0,0,0,.18)); }
.guest-footer { margin-top: 20px; color: rgba(255,255,255,.72); font-size: 12px; line-height: 1.5; }
.brand-mark { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 24px; border-radius: 22px; background: var(--brand-primary); color: #fff; font-size: 28px; font-weight: 800; text-transform: uppercase; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 11px; font-size: 13px; }
.login-card { background: rgba(255,255,255,.98); border: 1px solid rgba(255,255,255,.45); border-radius: 24px; padding: 40px; text-align: left; box-shadow: 0 28px 70px rgba(0,0,0,.28); }
.login-badge { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; margin-bottom: 20px; border-radius: 999px; color: var(--brand-primary); background: color-mix(in srgb, var(--brand-primary) 10%, white); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.login-card h1 { margin: 0 0 10px; font-size: 32px; letter-spacing: -.04em; }
.login-intro { color: var(--portal-muted); line-height: 1.65; margin-bottom: 26px; }
.login-card .btn-lg { display: flex; justify-content: center; align-items: center; gap: 10px; min-height: 52px; font-weight: 700; }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 2px; color: #344158; font-size: 13px; font-weight: 750; }
.login-form .form-control { margin-bottom: 5px; }
.login-form .btn { margin-top: 7px; }
.login-code { text-align: center; font-size: 22px; font-weight: 750; letter-spacing: .15em; }
.login-cancel-form { margin-top: 14px; text-align: center; }
.login-cancel-form button { padding: 3px; border: 0; background: transparent; color: var(--brand-primary); font-size: 13px; font-weight: 700; }
.login-help { margin: 25px 0 0; padding-top: 20px; border-top: 1px solid var(--portal-border); color: var(--portal-muted); font-size: 13px; text-align: center; }

.portal-app { min-height: 100vh; margin: 0; background: var(--portal-bg); }
.portal-shell { min-height: 100vh; display: flex; }
.portal-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 1040; display: flex; flex-direction: column; width: 270px; padding: 20px 16px; overflow-y: auto; background: var(--portal-sidebar); color: #fff; transition: transform .25s ease; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 4px 12px 22px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 16px; font-weight: 800; }
.sidebar-brand img { width: 42px; height: 42px; object-fit: contain; border-radius: 10px; background: #fff; padding: 4px; }
.portal-nav { display: grid; gap: 5px; padding: 22px 0; }
.portal-nav a { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border-radius: 10px; color: #aeb8cd; font-size: 14px; font-weight: 600; transition: .18s ease; }
.portal-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.portal-nav a.active { background: var(--brand-primary); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--brand-primary) 25%, transparent); }
.portal-nav i { width: 22px; font-size: 20px; text-align: center; }
.nav-count { margin-left: auto; min-width: 23px; height: 23px; display: grid; place-items: center; padding: 0 6px; border-radius: 999px; background: #ff4d67; color: #fff; font-size: 11px; font-weight: 800; }
.nav-count.zero { background: rgba(255,255,255,.1); color: #8794ad; }
.sidebar-help { display: flex; gap: 12px; margin-top: auto; padding: 15px; border: 1px solid rgba(255,255,255,.08); border-radius: 14px; background: rgba(255,255,255,.04); }
.sidebar-help > i { color: #85a4ff; font-size: 24px; }
.sidebar-help strong, .sidebar-help span { display: block; }
.sidebar-help strong { margin-bottom: 4px; font-size: 13px; }
.sidebar-help span { color: #8e9bb4; font-size: 11px; line-height: 1.5; }
.portal-main { width: calc(100% - 270px); min-height: 100vh; margin-left: 270px; display: flex; flex-direction: column; }
.portal-topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; min-height: 76px; padding: 0 28px; border-bottom: 1px solid var(--portal-border); background: rgba(255,255,255,.94); backdrop-filter: blur(12px); }
.sidebar-toggle { display: none; border: 0; background: transparent; font-size: 24px; }
.topbar-title { display: grid; }
.topbar-title span { font-weight: 800; }
.topbar-title small { color: var(--portal-muted); }
.topbar-user { display: flex; align-items: center; gap: 11px; margin-left: auto; }
.user-avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: color-mix(in srgb, var(--brand-primary) 13%, white); color: var(--brand-primary); font-weight: 800; }
.user-copy { display: grid; min-width: 150px; }
.user-copy strong { font-size: 13px; line-height: 1.3; }
.user-copy span { color: var(--portal-muted); font-size: 11px; }
.portal-content { width: 100%; margin: 0; padding: 30px; flex: 1; }
.portal-footer { padding: 15px 30px 24px; color: var(--portal-muted); font-size: 12px; text-align: center; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.page-heading h1 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 32px); letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--portal-muted); }
.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; color: var(--portal-muted); font-size: 13px; }
.portal-card { border: 1px solid var(--portal-border); border-radius: 16px; box-shadow: 0 8px 24px rgba(20,33,61,.045); overflow: hidden; }
.portal-card .card-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 22px; border-color: var(--portal-border); background: #fff; }
.portal-card .card-header h2 { margin: 0 0 3px; font-size: 17px; }
.portal-card .card-header p { margin: 0; color: var(--portal-muted); font-size: 12px; }
.portal-card .card-header > a { color: var(--brand-primary); font-size: 13px; font-weight: 700; }
.portal-card .card-body { padding: 24px; }
.status-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.status-grid.stage-1 .status-card { grid-column: span 12; }
.status-grid.stage-2 .status-card { grid-column: span 3; }
.status-grid.stage-3 .status-card { grid-column: span 3; }
.status-grid.stage-3 .status-card:nth-child(n+5) { grid-column: span 4; }
.status-card { position: relative; display: flex; align-items: center; gap: 16px; min-height: 118px; padding: 22px; overflow: hidden; border: 1px solid var(--portal-border); border-radius: 20px; background: #fff; color: var(--portal-text); box-shadow: 0 10px 28px rgba(20,33,61,.055); transition: transform .18s ease, box-shadow .18s ease; }
.status-card:hover { transform: translateY(-2px); box-shadow: 0 13px 30px rgba(20,33,61,.09); color: var(--portal-text); }
.status-icon { display: grid; place-items: center; width: 54px; height: 54px; flex: 0 0 54px; border-radius: 16px; background: color-mix(in srgb, var(--status-colour) 13%, white); color: var(--status-colour); font-size: 25px; }
.status-card strong, .status-card small { display: block; }
.status-card strong { font-size: 29px; line-height: 1; }
.status-card small { margin-top: 8px; color: var(--portal-muted); font-size: 13px; font-weight: 650; line-height: 1.25; }
.status-card.needs-attention { border-color: color-mix(in srgb, #ff4d67 36%, white); }
.attention-dot { position: absolute; top: 9px; right: 9px; display: grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 99px; background: #ff4d67; color: #fff; font-size: 10px; font-weight: 800; }
.ticket-table th { padding: 13px 20px; color: var(--portal-muted); background: #fbfcfe; border-bottom-color: var(--portal-border); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.ticket-table td { padding: 15px 20px; border-bottom-color: var(--portal-border); color: #4c586b; font-size: 13px; }
.ticket-table tr:last-child td { border-bottom: 0; }
.ticket-number { font-weight: 800; color: #e32732 !important; }
.ticket-subject { display: block; max-width: 400px; color: var(--portal-text); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-subject:hover { color: var(--brand-primary); }
.status-pill { display: inline-flex; align-items: center; min-height: 27px; padding: 5px 10px; border-radius: 999px; background: color-mix(in srgb, var(--status-colour) 12%, white); color: var(--status-colour); font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-pill.large { min-height: 34px; padding: 7px 13px; }
.icon-link { color: var(--portal-muted); font-size: 21px; }
.icon-link:hover { color: var(--brand-primary); }
.btn-view-ticket { display: inline-flex; align-items: center; gap: 6px; border: 1px solid color-mix(in srgb, var(--brand-primary) 28%, white); background: color-mix(in srgb, var(--brand-primary) 8%, white); color: var(--brand-primary); font-size: 11px; font-weight: 800; white-space: nowrap; }
.btn-view-ticket:hover, .btn-view-ticket:focus { border-color: var(--brand-primary); background: var(--brand-primary); color: #fff; }
.empty-state { padding: 70px 20px; text-align: center; }
.empty-state > i { color: #b6c0cf; font-size: 50px; }
.empty-state h2 { margin: 12px 0 5px; font-size: 18px; }
.empty-state p { margin-bottom: 18px; color: var(--portal-muted); }
.ticket-toolbar { flex-wrap: wrap; }
.ticket-search { display: flex; align-items: center; gap: 8px; min-width: min(100%, 430px); padding: 5px 5px 5px 12px; border: 1px solid var(--portal-border); border-radius: 11px; }
.ticket-search > i { color: var(--portal-muted); }
.ticket-search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; }
.result-count { color: var(--portal-muted); font-size: 12px; }
.form-card { width: 100%; max-width: none; }
.form-label { color: #344158; font-size: 13px; font-weight: 750; }
.form-control, .form-select { min-height: 46px; border-color: #dfe5ed; border-radius: 10px; }
textarea.form-control { min-height: auto; }
.form-control:focus, .form-select:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 13%, transparent); }
.attachment-button { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px dashed #bac4d2; border-radius: 10px; background: #fbfcfe; color: #506079; cursor: pointer; font-size: 13px; font-weight: 700; }
.attachment-button:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.attachment-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.selected-files { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.selected-files span { padding: 5px 8px; border-radius: 7px; background: #eef2f7; color: #59677d; font-size: 11px; }
.form-text { display: block; margin-top: 7px; color: var(--portal-muted); }
.ticket-heading { align-items: end; }
.ticket-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; border: 1px solid var(--portal-border); border-radius: 16px; background: #fff; box-shadow: 0 8px 24px rgba(20,33,61,.035); overflow: hidden; }
.ticket-summary > div { min-width: 0; padding: 17px 20px; border-right: 1px solid var(--portal-border); }
.ticket-summary > div:last-child { border-right: 0; }
.ticket-summary span, .ticket-summary strong { display: block; }
.ticket-summary span { margin-bottom: 5px; color: var(--portal-muted); font-size: 10px; font-weight: 750; letter-spacing: .055em; text-transform: uppercase; }
.ticket-summary strong { overflow: hidden; color: #344158; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.ticket-layout { display: grid; gap: 22px; }
.conversation-card .card-body { padding: 22px; background: #f8fafd; }
.conversation { display: grid; gap: 16px; }
.message { display: flex; align-items: flex-start; gap: 14px; width: 100%; max-width: none; }
.message.customer { margin: 0; flex-direction: row; }
.message-avatar { display: grid; place-items: center; width: 52px; height: 52px; flex: 0 0 52px; overflow: hidden; border-radius: 15px; background: #e9edf4; color: #627087; font-size: 22px; }
.message-avatar img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.message.customer .message-avatar { background: color-mix(in srgb, var(--brand-primary) 12%, white); color: var(--brand-primary); }
.message-body { min-width: 0; flex: 1; min-height: 96px; padding: 20px 22px; border: 1px solid var(--portal-border); border-radius: 4px 16px 16px 16px; background: #fff; box-shadow: 0 6px 18px rgba(20,33,61,.035); }
.message.customer .message-body { border-radius: 4px 16px 16px 16px; background: color-mix(in srgb, var(--brand-primary) 3.5%, white); }
.message-meta { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 10px; }
.message-meta strong { font-size: 13px; }
.message-author { display: flex; align-items: baseline; gap: 6px; }
.message-author span { color: var(--brand-primary); font-size: 11px; font-weight: 750; }
.message-meta time { color: var(--portal-muted); font-size: 11px; white-space: nowrap; }
.message-copy { color: #3f4c60; font-size: 14px; line-height: 1.7; overflow-wrap: anywhere; }
.message-attachments { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 13px; }
.message-attachments span, .message-attachments a { display: inline-flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 7px; background: #eef2f7; color: #42516a; font-size: 11px; font-weight: 700; }
.message-attachments a:hover { background: color-mix(in srgb, var(--brand-primary) 12%, white); color: var(--brand-primary); }
.conversation-empty { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 120px; color: var(--portal-muted); font-size: 13px; }
.conversation-empty i { font-size: 22px; }
.reply-card { position: static; }
.closed-notice { display: flex; align-items: center; gap: 13px; padding: 15px; border-radius: 11px; background: #f2f4f7; }
.closed-notice > i { color: #68758a; font-size: 24px; }
.closed-notice strong, .closed-notice span { display: block; }
.closed-notice span { color: var(--portal-muted); font-size: 12px; }
.sidebar-backdrop { display: none; }
.portal-nav-notice { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed rgba(255,255,255,.14); border-radius: 10px; color: #8e9bb4; font-size: 13px; }
.portal-nav-notice i { width: 22px; color: #85a4ff; font-size: 20px; text-align: center; }
.progress-banner { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; padding: 15px 18px; border: 1px solid #f3d58b; border-radius: 14px; background: #fff9e9; color: #795613; }
.progress-banner > i { font-size: 25px; }
.progress-banner strong, .progress-banner span { display: block; }
.progress-banner strong { margin-bottom: 2px; font-size: 14px; }
.progress-banner span { color: #8b6b2b; font-size: 12px; }
.maintenance-card { width: min(100%, 760px); margin: clamp(30px, 9vh, 110px) auto; padding: clamp(34px, 6vw, 70px); border: 1px solid var(--portal-border); border-radius: 24px; background: #fff; box-shadow: 0 24px 60px rgba(20,33,61,.09); text-align: center; }
.maintenance-icon { display: grid; place-items: center; width: 78px; height: 78px; margin: 0 auto 22px; border-radius: 22px; background: color-mix(in srgb, var(--brand-primary) 12%, white); color: var(--brand-primary); font-size: 34px; }
.maintenance-label { display: inline-flex; padding: 7px 12px; border-radius: 999px; background: #fff5db; color: #9b6900; font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.maintenance-card h1 { margin: 20px 0 12px; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.04em; }
.maintenance-card p { max-width: 560px; margin: 0 auto; color: var(--portal-muted); font-size: 16px; line-height: 1.7; }

@media (max-width: 1200px) {
    .status-grid .status-card, .status-grid.stage-3 .status-card:nth-child(n+5) { grid-column: span 6; }
}
@media (max-width: 991px) {
    .portal-sidebar { transform: translateX(-100%); }
    .portal-sidebar.open { transform: translateX(0); }
    .portal-main { width: 100%; margin-left: 0; }
    .sidebar-toggle { display: inline-grid; margin-right: 13px; }
    .sidebar-backdrop { position: fixed; inset: 0; z-index: 1030; background: rgba(6,10,20,.52); }
    .sidebar-backdrop.show { display: block; }
    .ticket-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ticket-summary > div:nth-child(2) { border-right: 0; }
    .ticket-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--portal-border); }
}
@media (max-width: 767px) {
    .portal-content { padding: 22px 16px; }
    .portal-topbar { padding: 0 16px; }
    .topbar-title { display: none; }
    .user-copy { display: none; }
    .status-grid .status-card, .status-grid.stage-3 .status-card:nth-child(n+5) { grid-column: span 6; }
    .page-heading { align-items: flex-start; }
    .page-heading > .btn { white-space: nowrap; }
    .ticket-table th:nth-child(1), .ticket-table td:nth-child(1), .ticket-table th:nth-child(4), .ticket-table td:nth-child(4), .ticket-table th:nth-child(5), .ticket-table td:nth-child(5) { display: none; }
    .login-card { padding: 28px 22px; border-radius: 20px; }
    .message-meta { display: grid; gap: 2px; }
    .message { max-width: 100%; }
}
@media (max-width: 420px) {
    .status-grid .status-card, .status-grid.stage-3 .status-card:nth-child(n+5) { grid-column: span 12; }
    .page-heading { display: grid; }
}
