/* ==========================================================================
   Kedaimini Support Portal — Theme
   Overrides osTicket default styles to match Kedaimini design system.
   Design principle: Clean Minimalism with Material Elevation hints.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */
:root {
    /* Colors */
    --color-primary:        #2563eb;
    --color-primary-hover:  #1d4ed8;
    --color-primary-light:  #eff6ff;
    --color-primary-muted:  #93c5fd;
    --color-danger:         #dc2626;
    --color-danger-light:   #fef2f2;
    --color-success:        #16a34a;
    --color-success-light:  #f0fdf4;
    --color-warning:        #d97706;
    --color-warning-light:  #fffbeb;
    --color-info:           #0284c7;
    --color-info-light:     #f0f9ff;

    /* Neutrals */
    --color-bg:             #f5f7fa;
    --color-surface:        #ffffff;
    --color-border:         #e5e7eb;
    --color-border-strong:  #d1d5db;
    --color-text:           #111827;
    --color-text-secondary: #374151;
    --color-muted:          #6b7280;
    --color-subtle:         #9ca3af;

    /* Status badge colors */
    --status-open-bg:       #dcfce7;
    --status-open-text:     #166534;
    --status-closed-bg:     #f3f4f6;
    --status-closed-text:   #374151;
    --status-pending-bg:    #fef9c3;
    --status-pending-text:  #854d0e;
    --status-resolved-bg:   #dbeafe;
    --status-resolved-text: #1e40af;

    /* Typography */
    --font-body:            'Inter', system-ui, -apple-system, sans-serif;
    --font-mono:            'JetBrains Mono', 'Fira Code', monospace;

    /* Type scale */
    --text-xs:   0.75rem;
    --text-sm:   0.875rem;
    --text-base: 1rem;
    --text-lg:   1.125rem;
    --text-xl:   1.25rem;
    --text-2xl:  1.5rem;
    --text-3xl:  1.875rem;

    /* Spacing */
    --space-1:  0.25rem;
    --space-2:  0.5rem;
    --space-3:  0.75rem;
    --space-4:  1rem;
    --space-5:  1.25rem;
    --space-6:  1.5rem;
    --space-8:  2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Borders */
    --radius-sm:   4px;
    --radius-md:   8px;
    --radius-lg:   12px;
    --radius-xl:   16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs:  0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md:  0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg:  0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.05);
    --shadow-xl:  0 20px 60px rgba(0, 0, 0, 0.12);

    /* Transitions */
    --duration-fast:   150ms;
    --duration-base:   200ms;
    --duration-slow:   300ms;
    --ease-default:    cubic-bezier(0.4, 0, 0.2, 1);

    /* Z-index */
    --z-base:    1;
    --z-sticky:  100;
    --z-overlay: 9998;
    --z-modal:   9999;
}

/* --------------------------------------------------------------------------
   Base / Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 100%;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body,
input,
select,
textarea,
button {
    font-family: var(--font-body);
}

/* --------------------------------------------------------------------------
   Legacy Bootstrap 2 utility shims — osTicket templates rely on these
   -------------------------------------------------------------------------- */
.pull-left  { float: left !important; }
.pull-right { float: right !important; }
.flush-left  { margin-left: 0 !important; }
.flush-right { margin-right: 0 !important; }
.clearfix::after { content: ''; display: table; clear: both; }
.clear { clear: both; }

/* --------------------------------------------------------------------------
   Legacy layout containers — neutralize, Bootstrap takes over
   -------------------------------------------------------------------------- */
#container {
    max-width: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    box-shadow: none;
    width: 100%;
}

/* Hide legacy header/nav — replaced by Bootstrap navbar in header.inc.php */
#header { display: none !important; }
#nav    { display: none !important; }

/* osTicket nav PHP uses the nav key (e.g. "status", "open", "tickets") as a class
   on each <a class="nav-link {key}">. Prevent badge/status rules from styling them. */
.navbar .nav-link {
    display: block !important;
    font-size: 1rem !important;
    font-weight: 400 !important;
    padding: 0.5rem 1rem !important;
    border-radius: 0 !important;
    background-color: transparent !important;
    color: rgba(0,0,0,0.55) !important;
    line-height: 1.5 !important;
    white-space: normal !important;
    text-shadow: none !important;
    vertical-align: baseline !important;
}

.navbar .nav-link:hover,
.navbar .nav-link:focus {
    color: rgba(0,0,0,0.7) !important;
    text-decoration: none !important;
}

.navbar .nav-link.active {
    color: #000 !important;
    font-weight: 500 !important;
}

/* Hide legacy inline alert bars — replaced by Bootstrap alerts in header.inc.php */
.error_bar,
.warning_bar,
.notice_bar { display: none !important; }

/* Legacy footer — replaced by Bootstrap footer in footer.inc.php */
#footer { display: none !important; }

/* --------------------------------------------------------------------------
   Content area
   -------------------------------------------------------------------------- */
#content {
    background: transparent;
    padding: 0;
    margin: 0;
    min-height: 400px;
    height: auto;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-body);
    color: var(--color-text);
    font-weight: 600;
    line-height: 1.3;
    margin-top: 0;
    margin-bottom: var(--space-4);
}

h1 { font-size: var(--text-2xl); font-weight: 600; color: var(--color-text); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

.subject { font-size: var(--text-xl); color: var(--color-text); }

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-default);
}

.link {
    color: var(--color-primary);
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-default);
}

a:hover, .link:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
    cursor: pointer;
}

a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.faded, .muted { color: var(--color-muted); }
.text-muted    { color: var(--color-muted) !important; }

small  { font-size: var(--text-sm); }
strong { font-weight: 600; }

code, pre, .mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: var(--space-6) 0;
}

/* --------------------------------------------------------------------------
   Card — wraps major osTicket sections
   -------------------------------------------------------------------------- */
.homepageSection,
.ticket-view,
#ticketForm,
.login-box-parent,
#clientLogin,
#reply,
#ticketInfo,
#kb,
#faq,
.faq-content,
.search.well {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
}

/* Landing page action blocks */
#landing_page {
    margin-top: var(--space-4);
}

#landing_page #new_ticket,
#landing_page #check_status {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6) var(--space-8);
    width: auto;
    padding-left: var(--space-6);
    background-image: none;
    transition: box-shadow var(--duration-base) var(--ease-default),
                border-color var(--duration-base) var(--ease-default);
}

#landing_page #new_ticket:hover,
#landing_page #check_status:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary-muted);
}

#landing_page h1,
#landing_page h2,
#landing_page h3 {
    margin-bottom: var(--space-3);
}

/* --------------------------------------------------------------------------
   Forms — Bootstrap-style appearance
   -------------------------------------------------------------------------- */
label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-1);
    cursor: pointer;
}

label.required,
span.required {
    font-weight: 600;
}

label.required::after,
span.required::after {
    content: ' *';
    color: var(--color-danger);
}

label.inline {
    display: inline;
    width: auto;
    padding: 0 var(--space-2);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="url"],
textarea,
select {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm) + 2px;
    border-radius: 6px;
    transition: border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
    appearance: none;
    -webkit-appearance: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7280' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

textarea {
    resize: vertical;
    min-height: 120px;
    width: 100% !important;
    max-width: 100%;
}

input[type="file"] {
    font-size: var(--text-sm);
    color: var(--color-muted);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    display: inline;
    margin-right: var(--space-2);
    accent-color: var(--color-primary);
}

/* Form table layout — prevent overflow on mobile */
table { width: 100% !important; }
td    { padding: var(--space-2) var(--space-1); vertical-align: top; }

/* Override osTicket fixed widths on form textareas */
#ticketForm td textarea,
#clientLogin td textarea,
#ticketForm div textarea,
#clientLogin div textarea {
    width: 100% !important;
    max-width: 100%;
}

#reply textarea {
    width: 100% !important;
}

#ticketForm > table {
    table-layout: auto;
}

#ticketForm > table td {
    width: auto;
}

/* Error states */
.error input,
#ticketForm div.error input,
#clientLogin div.error input {
    border-color: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.error label,
#ticketForm div.error label,
#clientLogin div.error label {
    color: var(--color-danger);
}

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

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
input[type="submit"],
input[type="button"],
input[type="reset"],
button[type="submit"],
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 500;
    color: #ffffff;
    background-color: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.5;
    transition: background-color var(--duration-fast) var(--ease-default),
                border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default),
                transform var(--duration-fast) var(--ease-default);
    -webkit-appearance: none;
    appearance: none;
    white-space: nowrap;
    min-height: 38px;
}

input[type="submit"]:hover,
input[type="button"]:hover,
button[type="submit"]:hover,
.button:hover {
    background-color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: #ffffff;
    text-decoration: none;
    box-shadow: var(--shadow-sm);
}

input[type="submit"]:focus-visible,
input[type="button"]:focus-visible,
button[type="submit"]:focus-visible,
.button:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

input[type="submit"]:active,
input[type="button"]:active,
button[type="submit"]:active,
.button:active {
    transform: translateY(1px);
    box-shadow: none;
}

.btn-secondary,
.button.secondary {
    background-color: transparent;
    color: var(--color-primary);
    border-color: var(--color-border-strong);
}

.btn-secondary:hover,
.button.secondary:hover {
    background-color: var(--color-primary-light);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* Legacy .blue.button / .green.button overrides */
.blue.button,
.blue.button:visited {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.blue.button:hover { background-color: var(--color-primary-hover); }

.green.button,
.green.button:visited {
    background-color: var(--color-success);
    border-color: var(--color-success);
    color: #fff;
}

/* Action buttons (small inline controls) */
.action-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 3px var(--space-3);
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-secondary) !important;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    line-height: 1.5;
    transition: background-color var(--duration-fast) var(--ease-default);
    background-image: none;
    box-shadow: var(--shadow-xs);
    margin-left: 0;
}

.action-button:hover {
    background-color: var(--color-bg);
    border-color: var(--color-primary-muted);
}

.action-button span,
.action-button a {
    color: var(--color-text-secondary) !important;
}

/* --------------------------------------------------------------------------
   Alert / notice messages (inline, within #content)
   -------------------------------------------------------------------------- */
#msg_notice,
#msg_warning,
#msg_error,
#msg_info {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    font-weight: 500;
    background-image: none;
    height: auto;
    line-height: 1.5;
}

#msg_notice {
    background-color: var(--color-success-light);
    border: 1px solid #bbf7d0;
    color: var(--color-success);
}

#msg_warning,
.warning-banner {
    background-color: var(--color-warning-light);
    border: 1px solid #fde68a;
    color: var(--color-warning);
    height: auto;
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    line-height: 1.5;
    font-size: var(--text-sm);
}

#msg_error {
    background-color: var(--color-danger-light);
    border: 1px solid #fecaca;
    color: var(--color-danger);
}

#msg_info {
    background-color: var(--color-info-light);
    border: 1px solid #bae6fd;
    color: var(--color-info);
}

.warning {
    background-color: var(--color-warning-light);
    border-left: 3px solid var(--color-warning);
    padding: var(--space-2) var(--space-4);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: normal;
}

.warning strong {
    text-transform: none;
    color: var(--color-warning);
    font-style: normal;
}

/* --------------------------------------------------------------------------
   Search bar
   -------------------------------------------------------------------------- */
.search.well {
    padding: var(--space-4);
    background-color: var(--color-surface) !important;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-5);
    margin-top: 0;
}

.searchbar .search,
.search-form .search {
    width: 100%;
    border: 1px solid var(--color-border-strong);
    border-radius: 6px;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    box-shadow: none;
    transition: border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
}

.searchbar .search:focus,
.search-form .search:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* --------------------------------------------------------------------------
   Ticket table
   -------------------------------------------------------------------------- */
#ticketTable {
    width: 100% !important;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

#ticketTable caption {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    color: var(--color-text-secondary);
    background: #f9fafb;
    border: 1px solid var(--color-border);
    border-bottom: none;
    font-weight: 600;
    font-size: var(--text-sm);
    caption-side: top;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

#ticketTable thead th {
    background: #f9fafb;
    border: none;
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

#ticketTable thead th a {
    color: var(--color-muted);
    font-weight: 600;
    text-decoration: none;
}

#ticketTable thead th a:hover {
    color: var(--color-primary);
    text-decoration: none;
}

#ticketTable tbody td {
    padding: var(--space-3) var(--space-4);
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-sm);
    color: var(--color-text);
    vertical-align: middle;
}

#ticketTable tbody tr:last-child td {
    border-bottom: none;
}

#ticketTable tbody tr {
    transition: background-color var(--duration-fast) var(--ease-default);
}

#ticketTable tbody tr:hover {
    background-color: var(--color-primary-light);
}

#ticketTable tbody tr.alt td {
    background: transparent;
}

/* infoTable (ticket detail sidebar table) */
.infoTable {
    background: #f9fafb;
    width: 100%;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.infoTable th {
    text-align: left;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-muted);
    background: #f9fafb;
    white-space: nowrap;
    width: 35%;
}

.infoTable td {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    color: var(--color-text);
}

table.padded tr > td,
table.padded tr > th {
    height: auto;
    padding: var(--space-2) var(--space-3);
}

table.custom-data {
    margin-top: var(--space-3);
    width: 100%;
}

table.custom-data th {
    width: 30%;
    background-color: #f9fafb;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-muted);
}

table .headline,
table.custom-data .headline {
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
    background-color: var(--color-surface);
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

/* Ticket source / status icons (legacy) */
.Icon {
    color: var(--color-primary);
    text-decoration: none;
    padding-left: 0;
    background-image: none;
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Status badges
   -------------------------------------------------------------------------- */
.label,
.badge,
.status {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    text-shadow: none;
    vertical-align: baseline;
}

/* Default (grey) */
.label,
.badge {
    background-color: var(--status-closed-bg);
    color: var(--status-closed-text);
}

/* Open — green */
.label.open,   .badge.open,   .status.open,
.label.active, .badge.active, .status.active {
    background-color: var(--status-open-bg);
    color: var(--status-open-text);
}

/* Closed — grey */
.label.closed, .badge.closed, .status.closed {
    background-color: var(--status-closed-bg);
    color: var(--status-closed-text);
}

/* Pending / overdue — amber */
.label.pending,  .badge.pending,  .status.pending,
.label.overdue,  .badge.overdue,  .status.overdue {
    background-color: var(--status-pending-bg);
    color: var(--status-pending-text);
}

/* Answered / resolved — blue */
.label.answered, .badge.answered, .status.answered,
.label.resolved, .badge.resolved, .status.resolved {
    background-color: var(--status-resolved-bg);
    color: var(--status-resolved-text);
}

.label-bare {
    background-color: transparent;
    border: 1px solid var(--color-border-strong);
    color: var(--color-muted);
    text-shadow: none;
}

/* State links in ticket list header */
.states small { font-size: var(--text-xs); }
.active.state  { font-weight: 700; color: var(--color-primary); }

/* --------------------------------------------------------------------------
   Ticket detail (#ticketInfo)
   -------------------------------------------------------------------------- */
#ticketInfo h1 {
    padding-bottom: var(--space-3);
    margin-bottom: var(--space-4);
    border-bottom: 2px solid var(--color-border);
    font-size: var(--text-2xl);
}

#ticketInfo h1 small {
    font-weight: 400;
    color: var(--color-muted);
    font-size: var(--text-base);
}

/* --------------------------------------------------------------------------
   Thread entries
   -------------------------------------------------------------------------- */
#ticketThread {
    position: relative;
    z-index: var(--z-base);
    border-bottom: 2px solid var(--color-border);
}

#ticketThread::before {
    border-left: 2px dotted var(--color-border);
    position: absolute;
    margin-left: 74px;
    z-index: -1;
    content: "";
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
}

.thread-entry {
    margin-bottom: var(--space-4);
}

.thread-entry.avatar    { margin-left: 60px; }
.thread-entry.response.avatar { margin-right: 60px; margin-left: 0; }

.thread-entry > .avatar {
    margin-left: -60px;
    display: inline-block;
    width: 48px;
    height: auto;
    border-radius: var(--radius-md);
}

.thread-entry.response > .avatar {
    margin-left: initial;
    margin-right: -60px;
}

img.avatar           { border-radius: inherit; }
.avatar > img.avatar { width: 100%; height: auto; }

.thread-entry .header {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-size: var(--text-sm);
}

.thread-entry.response .header {
    background: #f3f4f6;
}

.thread-entry.message .header {
    background: var(--color-primary-light);
    border-color: #bfdbfe;
}

.thread-entry .header .title {
    max-width: 100%;
    vertical-align: bottom;
    display: inline-block;
    margin-left: var(--space-4);
    font-weight: 500;
}

.thread-entry .thread-body {
    border: 1px solid var(--color-border);
    border-top: none;
    border-bottom: 2px solid var(--color-border-strong);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: var(--space-4);
    background: var(--color-surface);
    font-size: var(--text-sm);
    line-height: 1.7;
}

.thread-body .attachments {
    background-color: #f9fafb;
    margin: 0 calc(-1 * var(--space-4));
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    position: relative;
    top: var(--space-4);
}

.thread-body .attachments a,
.thread-body .attachments a:hover { text-decoration: none; }

.thread-body .attachment-info {
    margin-right: var(--space-3);
    display: inline-block;
    width: 48%;
}

.thread-body .attachments .filesize { margin-left: var(--space-2); color: var(--color-muted); }

.thread-event {
    padding: 0 var(--space-1) var(--space-4);
    margin-left: 60px;
    font-size: var(--text-sm);
    color: var(--color-muted);
}

.thread-event img.avatar {
    vertical-align: middle;
    border-radius: var(--radius-sm);
    width: auto;
    max-height: 24px;
    margin: -3px var(--space-1) 0;
}

.thread-event .description {
    margin-left: -30px;
    padding-top: var(--space-1);
    padding-left: 30px;
    display: inline-block;
    width: calc(100% - 95px);
    line-height: 1.5;
}

.type-icon {
    border-radius: var(--radius-md);
    background-color: #f3f4f6;
    border: 1px solid var(--color-border);
    padding: 4px 6px;
    margin-right: var(--space-2);
    text-align: center;
    display: inline-block;
    font-size: var(--text-base);
    vertical-align: top;
}

.type-icon.dark {
    border-color: #4b5563;
    background-color: #6b7280;
    color: #fff;
}

/* --------------------------------------------------------------------------
   Reply form
   -------------------------------------------------------------------------- */
#reply {
    margin-top: var(--space-5);
    padding: var(--space-6);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

#reply h2 {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--text-lg);
}

#reply > table  { width: 100% !important; }
#reply table td { vertical-align: top; }

#reply input[type="text"],
#reply #response_options textarea {
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
}

/* --------------------------------------------------------------------------
   Login / register box
   -------------------------------------------------------------------------- */
#clientLogin {
    display: block;
    margin-top: var(--space-5);
    padding: var(--space-6);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    background: var(--color-surface) !important;
    background-image: none !important;
}

.login-box {
    width: 45%;
    display: table-cell;
    padding: var(--space-4);
    box-shadow: none;
}

.login-box-parent {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

#clientLogin .instructions {
    display: table-cell;
    padding-left: var(--space-6);
    padding-right: var(--space-10);
}

#clientLogin strong {
    font-size: var(--text-sm);
    color: var(--color-danger);
    display: block;
    margin-bottom: var(--space-3);
    font-weight: 500;
}

#clientLogin input[type="text"],
#clientLogin input[type="password"] {
    padding: var(--space-2) var(--space-3);
    border-radius: 6px;
    margin-bottom: var(--space-4);
    width: 100%;
}

#clientLogin input[type="submit"] {
    padding: var(--space-2) var(--space-5);
    border-radius: 6px;
}

/* External auth providers (OAuth) */
.external-auth + .external-auth { margin-top: var(--space-2); }

a.external-sign-in { text-decoration: none; }

.external-auth-box {
    vertical-align: middle;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-strong);
    display: inline-flex;
    align-items: center;
    transition: box-shadow var(--duration-fast) var(--ease-default);
}

.external-auth-box:hover { box-shadow: var(--shadow-sm); }

.external-auth-icon {
    display: inline-block;
    color: var(--color-text-secondary);
    width: 30px;
    padding: var(--space-2) var(--space-3);
    border-right: 1px solid var(--color-border);
}

.external-auth-name {
    color: var(--color-text-secondary);
    padding: var(--space-2) var(--space-3);
    line-height: 30px;
    font-size: var(--text-sm);
    font-weight: 500;
}

img.sign-in-image {
    border: none;
    max-height: 40px;
    max-width: 200px;
    width: auto;
    height: auto;
}

/* --------------------------------------------------------------------------
   Knowledge base — redesigned
   -------------------------------------------------------------------------- */

/* Hero search banner */
.kb-hero {
    background: linear-gradient(135deg, var(--color-primary-light) 0%, #e0eaff 100%);
    border: 1px solid #c7d7fc;
}

/* Category card icon */
.kb-icon-wrap {
    width: 40px;
    height: 40px;
    background: var(--color-primary-light);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* Category grid cards */
.kb-category-card {
    transition: box-shadow var(--duration-base) var(--ease-default),
                transform var(--duration-base) var(--ease-default);
    cursor: pointer;
}

.kb-category-card:hover {
    box-shadow: var(--shadow-md) !important;
    transform: translateY(-2px);
}

/* Description line clamp */
.kb-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Sub-category cards */
.kb-subcat-card {
    transition: background-color var(--duration-fast) var(--ease-default);
}

.kb-subcat-card:hover {
    background-color: var(--color-primary-light) !important;
}

/* Article body typography */
.faq-body {
    font-size: var(--text-base);
    line-height: 1.8;
    color: var(--color-text-secondary);
}

.faq-body h1, .faq-body h2, .faq-body h3, .faq-body h4 {
    color: var(--color-text);
    margin-top: var(--space-6);
    margin-bottom: var(--space-3);
}

.faq-body p { margin-bottom: var(--space-4); }

.faq-body ul, .faq-body ol {
    padding-left: var(--space-6);
    margin-bottom: var(--space-4);
}

.faq-body li { margin-bottom: var(--space-2); }

.faq-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    margin: var(--space-4) 0;
}

.faq-body a { text-decoration: underline; }

/* Attachment links */
.kb-attachment {
    color: var(--color-text-secondary);
    border-radius: var(--radius-sm);
    padding: 4px var(--space-1);
}

.kb-attachment:hover {
    background-color: var(--color-bg);
    color: var(--color-primary);
    text-decoration: none !important;
}

/* FAQ list articles in category page */
.list-group-item-action:hover .bi-chevron-right {
    color: var(--color-primary) !important;
}

/* min-width:0 utility for flex truncation */
.min-width-0 { min-width: 0; }

/* --------------------------------------------------------------------------
   Knowledge base — legacy selectors kept for backward compat
   -------------------------------------------------------------------------- */
#kb {
    margin: 0;
    padding: var(--space-6);
    overflow: hidden;
}

#kb > li {
    padding: var(--space-4);
    height: auto;
    overflow: hidden;
    margin: 0;
    background: none;
    border-bottom: 1px solid var(--color-border);
    display: block;
}

#kb > li:last-child { border-bottom: none; }

#kb > li h4 span   { color: var(--color-muted); }
#kb > li h4 a      { font-size: var(--text-sm); font-weight: 500; }

#kb > li > i {
    display: block;
    width: 32px;
    height: 32px;
    float: left;
    margin-right: var(--space-3);
    background: none;
    font-size: 1.5rem;
    color: var(--color-primary-muted);
}

.featured-category {
    margin-top: var(--space-3);
    width: 49.7%;
    display: inline-block;
    box-sizing: border-box;
    vertical-align: top;
}

.category-name {
    display: inline-block;
    font-weight: 500;
    font-size: var(--text-base);
}

.featured-category i {
    color: var(--color-primary-muted);
    display: inline-block;
    vertical-align: middle;
}

.article-headline { margin-left: 34px; }
.rtl .article-headline { margin-left: 0; margin-right: 34px; }

.article-teaser {
    font-size: var(--text-sm);
    line-height: 1.6;
    height: 3.2em;
    overflow: hidden;
    color: var(--color-muted);
}

.article-title { font-weight: 500; }

.faq-content .article-title {
    font-size: var(--text-2xl);
    margin-top: var(--space-4);
    font-weight: 600;
}

/* FAQ list */
#faq {
    clear: both;
    margin: 0;
    padding: var(--space-4);
}

#faq ol {
    font-size: var(--text-base);
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--color-border);
    list-style: none;
}

#faq ol li {
    margin: 0;
    padding: 0;
    color: var(--color-muted);
}

#faq ol li a {
    display: block;
    padding: var(--space-3) var(--space-2);
    height: auto;
    overflow: hidden;
    margin: 0;
    border-bottom: 1px solid var(--color-border);
    line-height: 1.5;
    padding-left: var(--space-4);
    background-image: none;
    color: var(--color-primary);
    font-size: var(--text-sm);
}

#faq ol li a:hover {
    background-color: var(--color-primary-light);
    text-decoration: none;
}

#faq .article-meta {
    padding: var(--space-2);
    background: #f9fafb;
    font-size: var(--text-xs);
    color: var(--color-muted);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* KB search */
#kb-search {
    padding: var(--space-3) 0;
    overflow: hidden;
}

#kb-search div {
    clear: both;
    overflow: hidden;
    padding-top: var(--space-2);
}

#kb-search #query,
#kb-search #cid {
    margin: 0;
    display: inline-block;
    float: left;
    width: 200px;
    margin-right: var(--space-2);
}

#kb-search #topic-id {
    margin: 0;
    display: inline-block;
    float: left;
    width: 100%;
}

#kb-search #searchSubmit {
    margin: 0;
    display: inline-block;
    float: left;
    position: relative;
    top: 2px;
}

#kb-search #breadcrumbs {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */
.sidebar {
    margin-bottom: var(--space-5);
    margin-left: var(--space-5);
    width: 215px;
}

.rtl .sidebar { margin-left: 0; margin-right: var(--space-5); }

.sidebar .content {
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    border-radius: var(--radius-md);
}

.sidebar .content:empty { display: none; }

.sidebar section .header {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}

.sidebar section + section { margin-top: var(--space-4); }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
#pagination {
    border: 0;
    margin: 0 0 var(--space-8) 0;
    padding: var(--space-3) 0;
    font-size: var(--text-sm);
}

#pagination li {
    border: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    display: inline;
}

#pagination li a {
    margin-right: 2px;
    display: block;
    float: left;
    padding: var(--space-1) var(--space-3);
    text-decoration: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-primary);
    transition: background-color var(--duration-fast) var(--ease-default);
}

#pagination li a:hover {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary-muted);
}

#pagination .active {
    color: var(--color-primary);
    font-weight: 700;
    margin-right: 2px;
    display: block;
    float: left;
    padding: var(--space-1) var(--space-3);
    background: var(--color-primary-light);
    border: 1px solid var(--color-primary-muted);
    border-radius: var(--radius-sm);
}

#pagination .previousOff,
#pagination .nextOff {
    color: var(--color-muted);
    display: block;
    float: left;
    font-weight: 600;
    padding: var(--space-1) var(--space-2);
}

#pagination .next a,
#pagination .previous a { font-weight: 600; }

/* --------------------------------------------------------------------------
   Grid helpers (legacy span4/span8 used in some views)
   -------------------------------------------------------------------------- */
/* NOTE: .row overflow must NOT be hidden — Bootstrap 5 row uses negative margins */

.span4 {
    display: inline-block;
    width: 29.5%;
    margin: 0 1%;
    vertical-align: top;
}

.span8 {
    display: inline-block;
    width: 66%;
    margin: 0 1%;
    vertical-align: top;
}

/* --------------------------------------------------------------------------
   Utility classes
   -------------------------------------------------------------------------- */
.centered  { text-align: center; }
.hidden    { display: none !important; }
.nowrap    { white-space: nowrap; }
.bleed     { margin: 0 !important; padding: 0 !important; }

.truncate {
    display: inline-block;
    width: auto;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

.image-hover a.action-button:hover,
.image-hover a.action-button {
    color: initial !important;
    text-decoration: none;
}

i.refresh {
    color: var(--color-success);
    font-size: var(--text-sm);
    vertical-align: middle;
}

/* Refresh indicator */
a i.icon-refresh,
a i.refresh {
    color: var(--color-primary);
}

/* Freetext file attachments */
.freetext-files {
    padding: var(--space-3);
    margin-top: var(--space-3);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background-color: #f9fafb;
}

.freetext-files .file {
    margin-right: var(--space-3);
    display: inline-block;
    width: 48%;
    padding-top: var(--space-1);
}

.freetext-files .title {
    font-weight: 600;
    margin-bottom: var(--space-1);
    font-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
   Overlay and loading modal
   -------------------------------------------------------------------------- */
#overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: var(--z-overlay);
    display: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-12);
    z-index: var(--z-modal);
    display: none;
    text-align: center;
    box-shadow: var(--shadow-xl);
    min-width: 200px;
}

#loading h4 {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

#loading p {
    color: var(--color-muted);
    font-size: var(--text-sm);
    margin: 0;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--space-4);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .loading-spinner { animation: none; border-top-color: var(--color-primary); }
    * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* --------------------------------------------------------------------------
   RTL support
   -------------------------------------------------------------------------- */
.rtl #clientLogin    { background-position: 5% 50%; }
.rtl .login-box      { box-shadow: none; }
.rtl .sidebar        { margin-left: 0; margin-right: var(--space-5); }
.rtl #nav li a       { padding-left: 10px; padding-right: 32px; }
.rtl .thread-entry.response.avatar { margin-right: 0; margin-left: 60px; }
.rtl .article-headline { margin-left: 0; margin-right: 34px; }

/* --------------------------------------------------------------------------
   Responsive overrides
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* Tables scroll horizontally on mobile */
    #ticketTable,
    table.custom-data {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Form tables stack on mobile */
    #ticketForm > table,
    #clientLogin > table {
        display: block;
    }

    #ticketForm > table td,
    #clientLogin > table td {
        display: block;
        width: 100% !important;
    }

    .login-box {
        display: block;
        width: 100%;
    }

    .featured-category { width: 100%; }

    .span4,
    .span8 {
        display: block;
        width: 100%;
        margin: 0 0 var(--space-4) 0;
    }

    .sidebar {
        margin-left: 0;
        width: 100%;
    }

    .thread-entry.avatar         { margin-left: 0; }
    .thread-entry.response.avatar { margin-right: 0; }
    .thread-event                { margin-left: 0; }
    #ticketThread::before        { display: none; }

    #ticketTable thead th,
    #ticketTable tbody td {
        min-width: 100px;
    }

    .homepageSection,
    .ticket-view,
    #ticketForm,
    .login-box-parent,
    #clientLogin,
    #reply,
    #ticketInfo {
        padding: var(--space-4);
    }
}

@media (max-width: 480px) {
    #kb-search #query,
    #kb-search #cid {
        width: 100%;
        float: none;
        margin-right: 0;
    }

    .thread-entry .header .title { margin-left: var(--space-2); }
}
