:root {
    --brand-900: #0f172a;
    --brand-700: #1e293b;
    --brand-500: #475569;
    --accent-600: #2563eb;
    --accent-500: #3b82f6;
    --accent-50:  #eff6ff;
    --success-500: #10b981;
    --warn-500: #ef4444;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* Navbar */
.app-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0;
    position: relative; /* anchors the mobile drawer */
}

/* Hamburger toggle — desktop hides it, the @media (max-width:760px) block shows it. */
.nav-toggle {
    display: none;
    background: transparent;
    border: 0;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--brand-700);
    border-radius: var(--radius-sm);
}
.nav-toggle:hover { background: var(--accent-50); color: var(--accent-600); }
.nav-toggle svg { display: block; }

.app-nav .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px;
}

.app-nav .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--brand-900);
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.app-nav .brand .brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}

.app-nav .nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
}

.app-nav .nav-links a,
.app-nav .nav-links .nav-text {
    color: var(--brand-500);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.12s ease, color 0.12s ease;
}

.app-nav .nav-links a:hover { background: var(--accent-50); color: var(--accent-600); }
.app-nav .nav-links a.active { background: var(--accent-50); color: var(--accent-600); }

/* Buttons in the nav (e.g. "New Ticket") keep their white text */
.app-nav .nav-links a.btn,
.app-nav .nav-links a.btn:hover { color: #fff; background: var(--accent-600); border-color: var(--accent-600); }
.app-nav .nav-links a.btn:hover { background: #1d4ed8; border-color: #1d4ed8; }

.app-nav .nav-links .signed-in {
    color: var(--muted);
    font-size: 13px;
    margin-right: 4px;
}

/* Circular user avatar in the nav (clickable to /Identity/Account/Manage) */
.app-nav .nav-links a.user-avatar,
.app-nav .nav-links a.user-avatar:hover {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background: #fff;
    color: #000;
    border: 1.5px solid #000;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    margin-left: 4px;
}
.app-nav .nav-links a.user-avatar:hover { background: var(--accent-50); color: #000; border-color: #000; }

/* Notifications bell + dropdown */
.hd-bell-btn {
    background: transparent;
    border: 0;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--brand-700);
    border-radius: var(--radius-sm);
    position: relative;
    display: inline-flex;
    align-items: center;
}
.hd-bell-btn:hover { background: var(--accent-50); color: var(--accent-600); }
.hd-bell-badge {
    position: absolute;
    top: 2px; right: 0px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    background: #dc2626; color: #fff;
    border-radius: 999px;
    font-size: 10px; font-weight: 700;
    line-height: 16px; text-align: center;
}
.hd-bell-popup {
    position: absolute;
    top: 100%; right: 0;
    margin-top: 6px;
    width: 360px; max-height: 480px;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    z-index: 50;
}
.hd-bell-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.hd-bell-link {
    background: none; border: 0; cursor: pointer;
    color: var(--accent-600); font-size: 12px; padding: 0;
}
.hd-bell-link:hover { text-decoration: underline; }
.hd-bell-empty { padding: 18px 14px; color: var(--muted); font-size: 13px; }
.hd-bell-list { list-style: none; padding: 0; margin: 0; }
.hd-bell-item { border-bottom: 1px solid var(--border); }
.hd-bell-item:last-child { border-bottom: 0; }
.hd-bell-item.unread { background: #f0f9ff; }
.hd-bell-link-row { display: block; padding: 10px 14px; text-decoration: none; color: inherit; }
.hd-bell-link-row:hover { background: var(--bg); }
.hd-bell-title { font-size: 13px; font-weight: 600; color: var(--brand-900); }
.hd-bell-body { font-size: 12px; color: var(--text); margin-top: 2px; }
.hd-bell-time { font-size: 11px; color: var(--muted); margin-top: 4px; }

.app-nav button.linklike {
    background: none;
    border: 0;
    color: var(--brand-500);
    cursor: pointer;
    padding: 6px 12px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--radius-sm);
}
.app-nav button.linklike:hover { background: var(--accent-50); color: var(--accent-600); }

/* Layout */
.app-main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 6px; color: var(--brand-900); }
h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 8px; color: var(--brand-900); }
.page-subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.muted { color: var(--muted); }

/* Card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}
.card-header {
    margin: -24px -24px 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    font-weight: 600;
    color: var(--brand-900);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: var(--brand-900);
    color: #fff;
    text-decoration: none;
    border: 1px solid var(--brand-900);
    border-radius: var(--radius-sm);
    cursor: pointer;
    /* Reset user-agent button font + line-height so <a class="btn"> and
       <button class="btn"> render at the exact same height. */
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    line-height: 1.2;
    box-sizing: border-box;
    vertical-align: middle;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.12s ease;
}
button.btn { /* explicit overrides, since <button> defaults are stickier */
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.2;
    margin: 0;
}
.btn:hover { background: var(--brand-700); color: #fff; }
.btn-primary { background: var(--accent-600); border-color: var(--accent-600); }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-outline { background: var(--surface); color: var(--brand-900); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); border-color: #cbd5e1; color: var(--brand-900); }

/* Form */
.form-row { margin-bottom: 16px; }
.form-row label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--brand-700);
}
.form-row .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-row input[type=text],
.form-row input[type=email],
.form-row input[type=password],
.form-row input[type=date],
.form-row input[type=datetime-local],
.form-row input[type=time],
.form-row input[type=number],
.form-row input[type=tel],
.form-row input[type=url],
.form-row input[type=search],
.form-row select,
.form-row textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
    box-sizing: border-box;
    line-height: 1.4;
}
.form-row input[type=date],
.form-row input[type=datetime-local],
.form-row input[type=time] {
    /* Date/time inputs render their picker glyph differently per browser; pin a
       consistent height so they line up with their sibling text inputs. */
    min-height: 40px;
}
.form-row input[type=date]::-webkit-calendar-picker-indicator,
.form-row input[type=datetime-local]::-webkit-calendar-picker-indicator,
.form-row input[type=time]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
}
.form-row input[type=date]:hover::-webkit-calendar-picker-indicator,
.form-row input[type=datetime-local]:hover::-webkit-calendar-picker-indicator,
.form-row input[type=time]:hover::-webkit-calendar-picker-indicator {
    opacity: 1;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: 0;
    border-color: var(--accent-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Quill editor host */
.editor-host {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
    /* Always span the full width of the surrounding card. Without this, a parent
       flex/grid context can shrink the editor to its intrinsic content width and
       the description input feels narrower than the rest of the form. */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    /* Belt-and-suspenders: an inner Quill blot with unbreakable content (long URL,
       a huge inline image, a wide <pre>) shouldn't push the editor itself wider
       than its card. */
    overflow: hidden;
}
/* Force the Quill containers themselves to obey the host width and wrap long
   unbroken text instead of growing horizontally. Quill defaults to `white-space:
   pre-wrap` on .ql-editor but doesn't set overflow-wrap, so pasted URLs without
   spaces still blow out the column. */
.editor-host .ql-container.ql-snow,
.editor-host .ql-editor {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
}
.editor-host .ql-editor pre,
.editor-host .ql-editor code,
.editor-host .ql-editor table { max-width: 100%; overflow-x: auto; }
.editor-host:focus-within {
    border-color: var(--accent-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.editor-host .ql-toolbar.ql-snow {
    border: 0;
    border-bottom: 1px solid var(--border);
    border-top-left-radius: var(--radius-sm);
    border-top-right-radius: var(--radius-sm);
    background: #fafbfc;
}
.editor-host .ql-container.ql-snow {
    border: 0;
    border-bottom-left-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    min-height: 180px;
    font-family: inherit;
    font-size: 14px;
}
.editor-host .ql-editor { min-height: 180px; }
.editor-host .ql-editor img { cursor: pointer; max-width: 100%; }

/* Image-resize popup — appears above an image when clicked in the editor. */
.hd-img-resize {
    position: absolute;
    z-index: 9999;
    background: #1e293b;
    color: #fff;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 11px;
    display: none;
    align-items: center;
    gap: 4px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
    user-select: none;
}
.hd-img-resize-label {
    opacity: 0.65;
    padding-right: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.hd-img-resize button {
    background: rgba(255, 255, 255, 0.12);
    border: 0;
    color: inherit;
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}
.hd-img-resize button:hover { background: rgba(255, 255, 255, 0.28); }
.upload-status { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 16px; }

/* Hero (landing) */
.hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 56px 40px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.hero h1 { font-size: 32px; margin-bottom: 12px; }
.hero p.lead { font-size: 15px; color: var(--muted); margin: 0 0 24px; max-width: 560px; margin-left: auto; margin-right: auto; }
.hero .actions { display: flex; gap: 8px; justify-content: center; }

/* Pill / badges */
.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--accent-50);
    color: var(--accent-600);
    letter-spacing: 0.02em;
}
.pill.muted { background: #f1f5f9; color: var(--muted); }

/* Tables */
table.list {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
table.list th {
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}
table.list td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    color: var(--brand-900);
}
table.list tr:hover td { background: #fafbfc; }

/* Validation */
.field-validation-error,
span[data-valmsg-for] {
    color: var(--warn-500);
    font-size: 12px;
    margin-top: 4px;
    display: block;
}

/* KPI cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
}
.kpi-num { font-size: 24px; font-weight: 700; color: var(--brand-900); letter-spacing: -0.02em; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.kpi.kpi-warn .kpi-num { color: var(--warn-500); }

/* Filter bar */
.filter-bar { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.filter {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
}
.filter:hover { background: var(--surface); border-color: var(--border); color: var(--brand-900); }
.filter.active { background: var(--accent-600); color: #fff; border-color: var(--accent-600); }
/* Solid neutral pill for selected items inside the saved-views sidebar (left aside).
   Keeps the same shape as the top-action chips, just a much lighter, calmer tone. */
aside .filter.active { background: #e2e8f0; color: var(--brand-900); border-color: #cbd5e1; font-weight: 600; }
aside .filter.active:hover { background: #cbd5e1; color: var(--brand-900); border-color: #cbd5e1; }

/* Popup (filters menu, dropdowns) */
.popup-anchor { position: relative; display: inline-block; }
.popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 200;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    min-width: 380px;
    max-width: 480px;
    padding: 16px;
}
.popup[hidden] { display: none; }
.popup-section { margin-bottom: 14px; }
.popup-section-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.popup-checklist { max-height: 160px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); }
.popup-checklist label {
    display: flex; align-items: center; gap: 8px; padding: 4px 6px;
    border-radius: 4px; cursor: pointer; font-size: 13px;
    color: var(--text);
}
.popup-checklist label:hover { background: var(--accent-50); }
.popup-checklist input { margin: 0; }
.popup-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.filter-count-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px; padding: 0 6px;
    border-radius: 9px; background: var(--accent-600); color: #fff;
    font-size: 11px; font-weight: 600; margin-left: 6px;
}

/* Hide scrollbar but keep scrolling */
.no-scrollbar { scrollbar-width: none; -ms-overflow-style: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

/* Kanban drag-and-drop */
.kanban-col { transition: background 120ms ease; }
.kanban-col.drag-over { background: var(--accent-50) !important; outline: 2px dashed var(--accent-500); outline-offset: -2px; }
.kanban-card { cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }

/* Priority + status pills */
.pill.prio-p1 { background: #fee2e2; color: #991b1b; }
.pill.prio-p2 { background: #ffedd5; color: #9a3412; }
.pill.prio-p3 { background: #e0e7ff; color: #3730a3; }
.pill.prio-p4 { background: #f1f5f9; color: var(--muted); }

.pill.status-new { background: #dbeafe; color: #1e3a8a; }
.pill.status-ack { background: #ede9fe; color: #5b21b6; }
.pill.status-inprog { background: #fef3c7; color: #92400e; }
.pill.status-waiting { background: #f1f5f9; color: var(--muted); }
.pill.status-eng { background: #e0e7ff; color: #3730a3; }
.pill.status-resolved { background: #d1fae5; color: #065f46; }

/* Conversation messages */
.message {
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
}
.message:last-child { border-bottom: 0; padding-bottom: 0; }
.message-meta { margin-bottom: 8px; font-size: 13px; }
.message-body {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    /* Span the full width of the conversation card; long inline text wraps,
       it never gets shrunk by a parent flex layout. */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    /* Stop a single unbreakable child (huge image, very wide table) from
       expanding the card and forcing horizontal scroll on the whole page. */
    overflow-x: hidden;
}
.message-body img { max-width: 100%; height: auto; border-radius: 4px; margin: 4px 0; }
.message-body p { margin: 0 0 8px; overflow-wrap: anywhere; word-break: break-word; }
.message-body pre, .message-body code { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.message-body table { max-width: 100%; display: block; overflow-x: auto; }
.message-body a { overflow-wrap: anywhere; word-break: break-word; }
.message.message-internal { background: #fffbeb; border-left: 3px solid #f59e0b; padding-left: 14px; margin-left: -14px; padding-right: 14px; }

/* Conversation: every message is its own raised panel. Agent and client both
   sit on the LEFT (same side, not a left/right back-and-forth). Role is shown by
   the panel's border colour + the role badge, and agent (internal) messages are
   indented a little so you can tell them apart at a glance. System lines stay
   centered and quiet. */
.conversation { display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.conversation .message {
    border-bottom: 0;
    padding: 12px 14px;
    border-radius: 12px;
    max-width: 100%;
    width: fit-content;
    /* Each message panel is at least half the conversation width. */
    min-width: 50%;
    box-sizing: border-box;
    /* Each message reads as its own raised panel, not a line-separated row. */
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 2px 8px rgba(15, 23, 42, 0.06);
}
.conversation .message:last-child { padding-bottom: 12px; }
.conversation .message-meta { margin-bottom: 6px; }

/* Role colours — white panels, differentiated by a clear role-tinted border and
   the role badge on the meta line. */
.message.msg-staff  { background: #fff; border: 1px solid var(--accent-300, #a5b4fc); }
.message.msg-client { background: #fff; border: 1px solid #cbd5e1; }

/* Sides — agent and client both on the LEFT and both FULL width. Agent
   (internal) messages are indented a little (margin-left) so they read as
   distinct; the indent trims their width, so their right edge still lines up
   with the client panels. Same in both /Desk and /Portal. */
.conversation .msg-staff  { align-self: flex-start; width: 100%; margin-left: 32px; max-width: calc(100% - 32px); border-bottom-left-radius: 3px; }
.conversation .msg-client { align-self: flex-start; width: 100%; max-width: 100%; border-bottom-left-radius: 3px; }

/* Internal notes keep their amber treatment and follow the agent (indented, left). */
.conversation .message.message-internal {
    background: #fffbeb; border: 1px solid #fde68a; border-left: 3px solid #f59e0b;
    padding-left: 12px; padding-right: 12px;
    align-self: flex-start; width: 100%; margin-left: 32px; max-width: calc(100% - 32px);
}

/* System activity — a single clean, quiet, centered line (dot · text · time),
   not a full meta+body panel. Spans the row; overrides the 50% panel min-width. */
.message.msg-system {
    background: transparent; border: 0; box-shadow: none;
    max-width: 100%; width: 100%; min-width: 0; align-self: center;
    display: flex; align-items: center; justify-content: center;
    gap: 8px; padding: 3px 0; text-align: center;
    color: var(--muted, #64748b); font-size: 12.5px;
}
.msg-system .sys-dot { width: 5px; height: 5px; border-radius: 50%; background: #cbd5e1; flex: 0 0 auto; }
.msg-system .sys-text { min-width: 0; }
.msg-system .sys-text p { display: inline; margin: 0; }
.msg-system .sys-text > *:first-child { margin-top: 0; }
.msg-system .sys-time { color: #94a3b8; font-size: 11.5px; white-space: nowrap; }
.msg-system .sys-del { display: inline-flex; margin: 0; }
.msg-system .sys-del button { background: transparent; border: 0; color: #b91c1c; cursor: pointer; font-size: 11px; padding: 0 2px; line-height: 1; }

/* Role badge on the meta line */
.msg-role {
    font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
    text-transform: uppercase; letter-spacing: .03em; line-height: 1.7;
}
.msg-role.role-agent  { background: var(--accent-600, #4f46e5); color: #fff; }
.msg-role.role-client { background: #475569; color: #fff; }
.msg-role.role-email  { background: #0e7490; color: #fff; }

/* Detail grid (sidebar) */
dl.detail-grid { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
dl.detail-grid dt { color: var(--muted); }
dl.detail-grid dd { margin: 0; color: var(--brand-900); }

/* Flash messages — render as a toast overlay (top-right) instead of a block in the
   page flow, so saving/updating doesn't push content down. The data-autohide attribute
   on the element fades it out after the configured ms. */
.flash {
    position: fixed;
    top: 80px;            /* sits below the 56px navbar with breathing room */
    right: 20px;
    z-index: 9000;
    max-width: 420px;
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.10);
    font-size: 13.5px;
    line-height: 1.4;
    animation: flashSlideIn 0.22s ease-out;
}
@keyframes flashSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Auth pages (Sign in / Register / Forgot) ---------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(1200px 600px at 90% -10%, rgba(59, 130, 246, 0.10), transparent 60%),
        radial-gradient(900px 500px at -10% 110%, rgba(99, 102, 241, 0.08), transparent 60%),
        linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}

.auth-shell {
    width: 100%;
    max-width: 420px;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
    color: var(--brand-900);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.01em;
    text-decoration: none;
}
.auth-brand img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    display: block;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 12px 40px -12px rgba(15, 23, 42, 0.18);
}

.auth-head { margin-bottom: 22px; }
.auth-head h1 {
    font-size: 22px;
    line-height: 1.25;
    margin: 0 0 6px;
}
.auth-subtitle {
    color: var(--muted);
    font-size: 13.5px;
    margin: 0;
}

/* Inline alert (validation summary, login failed, etc.) */
.auth-alert { display: none; margin-bottom: 16px; }
.auth-alert[data-show="true"] { display: block; }
.auth-alert .validation-summary-errors,
.auth-alert > div {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.auth-alert ul { margin: 0; padding-left: 18px; }
.auth-alert ul:empty { display: none; }
.auth-alert li { line-height: 1.45; }

/* Label row (label + inline link, e.g. Forgot password) */
.label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}
.label-row label { margin-bottom: 0; }

.auth-link {
    color: var(--accent-600);
    text-decoration: none;
    font-size: 12.5px;
    font-weight: 500;
}
.auth-link:hover { text-decoration: underline; }
.auth-link-muted { color: var(--muted); }
.auth-link-muted:hover { color: var(--accent-600); }

/* Password field with show/hide */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.pwd-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    background: none;
    border: 0;
    color: var(--accent-600);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.pwd-toggle:hover { background: var(--accent-50); }
.pwd-toggle:focus-visible {
    outline: 2px solid var(--accent-500);
    outline-offset: 1px;
}

/* Remember-me checkbox */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 22px;
    font-size: 13px;
    color: var(--brand-700);
    cursor: pointer;
    user-select: none;
}
.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-600);
    cursor: pointer;
    margin: 0;
}

/* Primary submit */
.auth-submit {
    width: 100%;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.auth-submit.is-loading {
    opacity: 0.85;
    cursor: progress;
}

/* Footer in card + page legal line */
.auth-foot {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}
.auth-legal {
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
}

/* Mobile */
@media (max-width: 480px) {
    .auth-body { padding: 16px; }
    .auth-card { padding: 24px 20px; border-radius: 10px; }
    .auth-brand { margin-bottom: 18px; }
    .auth-head h1 { font-size: 20px; }
}

/* ----- Portal layout helpers (also apply on desktop) ----- */
.portal-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}
.portal-sidebar { flex: 0 0 220px; min-width: 220px; }
.portal-main    { flex: 1; min-width: 0; }
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.detail-split {
    display: grid;
    /* minmax(0, 1fr) — without the explicit 0, the track defaults to min-content
       and a single long unbroken string in a message (URL, token) expands the
       whole left column past the viewport. */
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 20px;
    align-items: start;
}
.detail-split > * { min-width: 0; }

/* ----- Mobile / tablet breakpoint for the whole client (Portal) UI ----- */
@media (max-width: 760px) {
    /* Layout edges */
    .app-main { padding: 16px 12px 40px; }
    h1 { font-size: 20px; }
    h2 { font-size: 16px; }

    /* Navigation: collapse to "logo + hamburger" on phones. Tapping the hamburger
       drops a vertical drawer with all links + the notifications bell + sign-out. */
    .app-nav .container {
        height: 56px;
        padding: 0 12px;
    }
    /* Brand wordmark stays visible next to the logo, just at a smaller size so
       logo + text + hamburger all fit comfortably on a phone bar. */
    .app-nav .brand { gap: 8px; min-width: 0; }
    .app-nav .brand .brand-text {
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: calc(100vw - 110px);
    }
    /* Show the hamburger. */
    .nav-toggle { display: inline-flex; align-items: center; }
    /* Default-hide the link strip and reposition it as a drawer when opened. */
    .app-nav .nav-links {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--surface);
        border-top: 1px solid var(--border);
        border-bottom: 1px solid var(--border);
        padding: 8px 12px;
        gap: 4px;
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
        z-index: 100;
    }
    .app-nav .nav-links.is-open { display: flex; }
    .app-nav .nav-links a,
    .app-nav .nav-links .nav-text,
    .app-nav button.linklike {
        padding: 10px 12px;
        font-size: 14px;
        text-align: left;
    }
    .app-nav .nav-links a.btn { padding: 10px 12px; font-size: 14px; text-align: center; }
    .app-nav .nav-links form { width: 100%; margin: 0; }
    .app-nav button.linklike { width: 100%; }

    /* Notifications bell inside the drawer: take the full row, render the popup
       inline (not absolutely positioned) so it doesn't overflow off-screen. */
    .hd-bell-wrap { width: 100%; }
    .hd-bell-btn { width: 100%; justify-content: flex-start; padding: 10px 12px; }
    .hd-bell-popup {
        position: static !important;
        width: 100%;
        margin-top: 4px;
        max-width: none;
        right: auto;
        box-shadow: none;
        border: 1px solid var(--border);
    }

    /* The user-avatar circle stays small but sits aligned with other rows. */
    .app-nav .nav-links a.user-avatar,
    .app-nav .nav-links a.user-avatar:hover { margin: 4px 0; align-self: flex-start; }

    /* Cards: tighter padding so inputs aren't crushed */
    .card { padding: 16px; }
    .card-header { margin: -16px -16px 12px; padding: 12px 16px; }
    .list-card { padding: 0 !important; }

    /* Portal page layout: sidebar stacks above the main column */
    .portal-layout { flex-direction: column; gap: 12px; }
    .portal-sidebar { flex: 0 0 auto; min-width: 0; width: 100%; }

    /* Form grids stack to one column */
    .form-grid-2 { grid-template-columns: 1fr; gap: 12px; }

    /* Wide tables: allow horizontal scroll inside their card so the row content stays
       readable instead of getting squished into illegible columns. The :has() rule
       catches every list-table card across Portal/Desk/Admin without needing each
       call site to opt in via .list-card. */
    .list-card,
    .card:has(table.list) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .list-card table.list,
    .card:has(table.list) table.list { min-width: 640px; }

    /* Detail pages (Desk Tickets, Desk Tasks, Portal Tickets) use a 2-col grid with a
       fixed-width sidebar. Stack on mobile so the conversation gets full width and
       the meta/details sidebar moves below it. */
    .detail-split {
        display: block !important;
    }
    .detail-split > * { width: 100% !important; }
    .detail-split > aside { margin-top: 12px; }

    /* Filter / popup widgets: never overflow viewport */
    .popup { left: 12px !important; right: 12px !important; max-width: calc(100vw - 24px); }

    /* Form rows: bigger tap targets for inputs/selects */
    .form-row input[type=text],
    .form-row input[type=email],
    .form-row input[type=password],
    .form-row input[type=date],
    .form-row input[type=number],
    .form-row input[type=tel],
    .form-row input[type=url],
    .form-row select,
    .form-row textarea {
        font-size: 16px; /* avoid iOS auto-zoom on focus */
    }

    /* Pills/badges shrink slightly */
    .pill { font-size: 11px; }
}

/* File dropzone — shared by the Portal "New Request" form and the Portal ticket
   reply form. Lived inline in Create.cshtml until the reply form needed it too. */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: 6px;
    background: var(--bg);
    padding: 18px;
    text-align: center;
    transition: background 120ms ease, border-color 120ms ease;
}
.dropzone.is-dragging { background: #eff6ff; border-color: #2563eb; }
.dropzone-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone-label { display: block; cursor: pointer; }
.dropzone-label strong { display: block; font-size: 14px; color: var(--brand-900); margin-bottom: 2px; }
.dropzone-label .dz-hint { font-size: 12px; color: var(--muted); }
.dropzone-list { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.dz-file {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    text-align: left;
}
.dz-name { flex: 1; word-break: break-all; }
.dz-size { color: var(--muted); font-size: 12px; }
.dz-remove {
    border: none; background: transparent; color: var(--muted);
    font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px;
    border-radius: 4px;
}
.dz-remove:hover { background: #fee2e2; color: #b91c1c; }
