/* ==========================================================================
   MIS Ticketing — custom theme system
   Four palettes via [data-theme]: warm (default) | mint | steel | mono.
   Tahoma (system sans) throughout. Technical feel:
   sharp-ish corners, compact spacing, thin crisp borders, minimal shadow.
   Built on top of Bootstrap's grid/utilities but overriding its look.
   ========================================================================== */

/* ---- Palettes ------------------------------------------------------------ */
:root,
[data-theme="warm"] {
  --accent:        #E08A3C;
  --accent-strong: #C6742A;
  --accent-soft:   #F3C79A;
  --bg-base:       #FBEFE6;
  --bg-surface:    #FFFFFF;
  --bg-alt:        #FDF6EF;
  --border:        #E7D5C4;
  --text:          #3D342C;
  --text-muted:    #8b7d70;
  --sidebar-bg:    #2f2a25;
  --sidebar-bg2:   #3c342c;
}
[data-theme="mint"] {
  --accent:        #3FA789;
  --accent-strong: #2F8770;
  --accent-soft:   #BFE6D9;
  --bg-base:       #F2F7F4;
  --bg-surface:    #FFFFFF;
  --bg-alt:        #EDF4F0;
  --border:        #D3E4DC;
  --text:          #26332E;
  --text-muted:    #6f827a;
  --sidebar-bg:    #21332D;
  --sidebar-bg2:   #2b423a;
}
[data-theme="steel"] {
  --accent:        #4A78A8;
  --accent-strong: #3A6191;
  --accent-soft:   #C2D5E8;
  --bg-base:       #F1F4F7;
  --bg-surface:    #FFFFFF;
  --bg-alt:        #EBEFF4;
  --border:        #D3DCE6;
  --text:          #2A323C;
  --text-muted:    #71808f;
  --sidebar-bg:    #232C36;
  --sidebar-bg2:   #2e3a46;
}
[data-theme="dark"] {
  --accent:        #6BA5D6;   /* soft blue — readable on dark */
  --accent-strong: #8FBCE4;   /* lighter on hover (dark UIs invert hover direction) */
  --accent-soft:   #2c3f52;   /* muted deep-blue for hover fills / avatars */
  --bg-base:       #16191d;
  --bg-surface:    #1f242a;
  --bg-alt:        #262c33;
  --border:        #333b44;
  --text:          #e6e9ec;
  --text-muted:    #9aa4ae;
  --sidebar-bg:    #101317;
  --sidebar-bg2:   #1a1e23;
}
/* Dark mode needs its own status colors: brighter, desaturated fills with
   light ink, since the light-theme pastels are illegible on dark surfaces. */
[data-theme="dark"] {
  --st-red:    #7d3b36; --st-red-ink:    #f2c6c1;
  --st-blue:   #345067; --st-blue-ink:   #cfe2f2;
  --st-green:  #2f5a41; --st-green-ink:  #c4e8d3;
  --st-yellow: #6b5426; --st-yellow-ink: #f0dca6;
}
/* Views hardcode Bootstrap text classes (text-dark, bg-light) that force dark
   text; in dark mode neutralise them so text follows the theme. Our badge
   ink colors are applied with !important below so they still win. */
[data-theme="dark"] .text-dark { color: var(--text) !important; }
[data-theme="dark"] .bg-light  { background: var(--bg-alt) !important; color: var(--text) !important; }
/* Warning badges: light ink beats a co-applied .text-dark utility. */
[data-theme="dark"] .badge.bg-warning.text-dark,
[data-theme="dark"] .badge.bg-warning { color: var(--st-yellow-ink) !important; }
[data-theme="dark"] .badge.bg-light { background: var(--bg-alt) !important; color: var(--text) !important; }
/* Card header "bg-warning text-dark" title text -> readable light ink. */
[data-theme="dark"] .card-header.bg-warning.text-dark { color: var(--st-yellow-ink) !important; }
/* Bootstrap's generic .table can set a dark --bs-table-color; force theme text. */
[data-theme="dark"] .table { --bs-table-color: var(--text); color: var(--text); }
[data-theme="dark"] .table > :not(caption) > * > * { color: var(--text); }

/* Status pastels — shared across themes, tuned to sit calmly on light bg. */
:root {
  --st-red:    #E9A79F; --st-red-ink:    #8a3a31;
  --st-blue:   #A9C6DE; --st-blue-ink:   #33607d;
  --st-green:  #A6D2B6; --st-green-ink:  #2e6a45;
  --st-yellow: #EBD199; --st-yellow-ink: #856322;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-pop: 0 4px 14px rgba(0,0,0,0.10);
}

/* ---- Base ---------------------------------------------------------------- */
/* Shrink the whole UI by ~2px: all rem-based sizes derive from this root.
   Browser default root is 16px; 14px drops every size by about 2 points. */
html { font-size: 14px; }
body {
  background-color: var(--bg-base);
  color: var(--text);
  font-family: Tahoma, Geneva, Verdana, system-ui, -apple-system, Segoe UI, sans-serif;
  font-size: 0.925rem;
  letter-spacing: 0.005em;
}
h1, h2, h3, h4, h5, .card-title, .navbar-brand, .sidebar-brand {
  font-family: Tahoma, Geneva, Verdana, system-ui, sans-serif;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }
.text-muted { color: var(--text-muted) !important; }

/* ---- App shell / sidebar ------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
  width: 60px; flex: 0 0 60px;
  background: var(--sidebar-bg);
  color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow: hidden;
  transition: width .16s ease, flex-basis .16s ease; z-index: 1030;
  border-right: 1px solid rgba(255,255,255,0.06);
}
.app-shell.sidebar-expanded .app-sidebar { width: 200px; flex-basis: 200px; }
.sidebar-top {
  display: flex; align-items: center; gap: 8px; padding: 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08); min-height: 54px;
}
.sidebar-toggle {
  background: transparent; border: none; color: #fff; font-size: 1rem;
  cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm);
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.1); }
.sidebar-brand { color: #fff; font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.sidebar-brand i { color: var(--accent); }
.sidebar-nav { flex: 1 1 auto; padding: 6px 0; overflow-y: auto; }
.sidebar-bottom { border-top: 1px solid rgba(255,255,255,0.08); padding: 6px 0; }
.sidebar-item {
  display: flex; align-items: center; gap: 13px; padding: 10px 19px;
  color: rgba(255,255,255,0.82); text-decoration: none; white-space: nowrap;
  border-left: 2px solid transparent; transition: background .12s, border-color .12s;
  font-size: 0.9rem;
}
.sidebar-item i { font-size: 1rem; width: 20px; text-align: center; flex: 0 0 20px; }
.sidebar-item:hover { background: rgba(255,255,255,0.06); color: #fff; border-left-color: var(--accent); text-decoration: none; }
.sidebar-label { opacity: 0; transition: opacity .15s; }
.app-shell.sidebar-expanded .sidebar-label { opacity: 1; }

/* ---- Main / topbar ------------------------------------------------------- */
.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  display: flex; align-items: center; gap: 14px; padding: 9px 20px;
  background: var(--bg-surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1020;
}
.topbar-title { font-family: Tahoma, Geneva, Verdana, sans-serif; font-weight: 600; font-size: 1rem; }
.topbar-user { margin-left: auto; color: var(--text); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.topbar-user i { color: var(--accent); font-size: 1.1rem; }
.role-badge { background: var(--accent-soft) !important; color: var(--text) !important; text-transform: capitalize; }
.app-content { padding: 14px 8px 40px; }
.auth-shell { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; background: var(--bg-base); }

/* ---- Theme switcher (topbar) --------------------------------------------- */
.theme-switch { display: flex; gap: 6px; align-items: center; }
.theme-dot {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; outline: none;
}
.theme-dot[data-set="warm"]  { background: #E08A3C; }
.theme-dot[data-set="mint"]  { background: #3FA789; }
.theme-dot[data-set="steel"] { background: #4A78A8; }
.theme-dot[data-set="dark"]  { background: #1f242a; border-color: #555; }
.theme-dot.active { border-color: var(--text); }

/* ---- Navbar (login etc. if used) ----------------------------------------- */
.navbar.bg-dark { background: var(--sidebar-bg) !important; }

/* ---- Cards --------------------------------------------------------------- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-header {
  border-bottom: 1px solid var(--border); font-weight: 600;
  background: var(--bg-alt); color: var(--text);
  border-top-left-radius: var(--radius) !important; border-top-right-radius: var(--radius) !important;
  font-size: 0.85rem; letter-spacing: 0.02em;
}
/* Recolor Bootstrap header utility classes to the theme accent / pastels */
.card-header.bg-primary, .bg-primary { background: var(--accent) !important; color: #fff !important; }
.card-header.bg-secondary, .bg-secondary { background: var(--text-muted) !important; color: #fff !important; }
.card-header.bg-dark { background: var(--sidebar-bg) !important; }
.card-header.bg-info,    .badge.bg-info    { background: var(--st-blue)   !important; color: var(--st-blue-ink)   !important; }
.card-header.bg-success, .badge.bg-success { background: var(--st-green)  !important; color: var(--st-green-ink)  !important; }
.card-header.bg-warning, .badge.bg-warning { background: var(--st-yellow) !important; color: var(--st-yellow-ink) !important; }
.card-header.bg-danger,  .badge.bg-danger  { background: var(--st-red)    !important; color: var(--st-red-ink)    !important; }

.text-bg-primary   { background: var(--accent) !important; color: #fff !important; }
.text-bg-secondary { background: var(--text-muted) !important; color: #fff !important; }
.text-bg-success   { background: var(--st-green)  !important; color: var(--st-green-ink)  !important; }
.text-bg-warning   { background: var(--st-yellow) !important; color: var(--st-yellow-ink) !important; }
.text-bg-info      { background: var(--st-blue)   !important; color: var(--st-blue-ink)   !important; }
.text-bg-danger    { background: var(--st-red)    !important; color: var(--st-red-ink)    !important; }
.text-bg-primary .btn-light, .text-bg-success .btn-light, .text-bg-warning .btn-light { --bs-btn-bg: #fff; }

/* ---- Badges -------------------------------------------------------------- */
.badge { font-weight: 600; border-radius: var(--radius-sm); letter-spacing: 0.02em; }

/* ---- Buttons — flat, tight, accent-driven -------------------------------- */
.btn { border-radius: var(--radius-sm); font-weight: 500; letter-spacing: 0.01em; box-shadow: none; }
.btn-primary {
  --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent-strong); --bs-btn-hover-border-color: var(--accent-strong);
  --bs-btn-active-bg: var(--accent-strong); --bs-btn-active-border-color: var(--accent-strong);
}
.btn-outline-primary {
  --bs-btn-color: var(--accent-strong); --bs-btn-border-color: var(--accent);
  --bs-btn-hover-bg: var(--accent); --bs-btn-hover-border-color: var(--accent);
  --bs-btn-active-bg: var(--accent-strong);
}
.btn-secondary {
  --bs-btn-bg: var(--text-muted); --bs-btn-border-color: var(--text-muted);
  --bs-btn-hover-bg: var(--text); --bs-btn-hover-border-color: var(--text);
}
.btn-success { --bs-btn-bg: var(--st-green); --bs-btn-border-color: #8ec6a3; --bs-btn-color: var(--st-green-ink); --bs-btn-hover-bg: #93cbaa; --bs-btn-hover-color: var(--st-green-ink); }
.btn-warning { --bs-btn-bg: var(--st-yellow); --bs-btn-border-color: #e6c884; --bs-btn-color: var(--st-yellow-ink); }
.btn-danger  { --bs-btn-bg: var(--st-red); --bs-btn-border-color: #eda096; --bs-btn-color: var(--st-red-ink); --bs-btn-hover-bg: #e5988d; --bs-btn-hover-color: var(--st-red-ink); }
.btn-info    { --bs-btn-bg: var(--st-blue); --bs-btn-border-color: #86b1d3; --bs-btn-color: var(--st-blue-ink); }
.btn-outline-secondary { --bs-btn-color: var(--text-muted); --bs-btn-border-color: var(--border); --bs-btn-hover-bg: var(--bg-alt); --bs-btn-hover-color: var(--text); }

/* ---- Tables — thin lines, compact ---------------------------------------- */
.table { --bs-table-bg: transparent; color: var(--text); font-size: 0.9rem; }
.table > :not(caption) > * > * { padding: 0.5rem 0.6rem; }
.table thead th {
  background: var(--bg-alt); color: var(--text-muted);
  border-bottom: 1px solid var(--border); text-transform: uppercase;
  font-size: 0.72rem; letter-spacing: 0.05em; font-weight: 600;
}
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-accent-bg: var(--bg-alt); background: var(--bg-alt); }
.table-hover > tbody > tr:hover > * { background: var(--accent-soft); }
td, th { border-color: var(--border) !important; }

/* ---- Forms --------------------------------------------------------------- */
.form-control, .form-select {
  background: var(--bg-surface); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); font-size: 0.9rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 0.15rem color-mix(in srgb, var(--accent) 28%, transparent);
}
.form-label, label { color: var(--text); font-weight: 500; font-size: 0.85rem; }

/* ---- Alerts -------------------------------------------------------------- */
.alert { border-radius: var(--radius); }
.alert-danger  { background: var(--st-red);    border-color: #eda096; color: var(--st-red-ink); }
.alert-warning { background: var(--st-yellow); border-color: #e6c884; color: var(--st-yellow-ink); }
.alert-success { background: var(--st-green);  border-color: #8ec6a3; color: var(--st-green-ink); }
.alert-info    { background: var(--st-blue);   border-color: #86b1d3; color: var(--st-blue-ink); }

/* ---- List groups & modals ------------------------------------------------ */
.list-group-item { background: var(--bg-surface); border-color: var(--border); color: var(--text); }
.list-group-item-action:hover { background: var(--bg-alt); }
.list-group-item.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-content { background: var(--bg-surface); border-radius: var(--radius); border: 1px solid var(--border); }
.modal-header.bg-danger { background: var(--st-red) !important; color: var(--st-red-ink) !important; }

/* ---- Ticket 3-column layout ---------------------------------------------- */
.ticket-layout { display: grid; grid-template-columns: 1fr 330px; gap: 16px; align-items: start; }
@media (max-width: 991.98px) { .ticket-layout { grid-template-columns: 1fr; } }
.ticket-thread .comment-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; margin-bottom: 10px; box-shadow: var(--shadow);
}
/* Comments sit slightly smaller than the ticket description so the original
   request stays the visual anchor of the thread. */
.ticket-thread .comment-card p { font-size: 0.9rem; line-height: 1.5; }
/* Preserve line breaks the user typed (and indentation) without unsafe raw
   HTML — the text stays HTML-escaped; CSS just honours the newlines. */
.ticket-thread .comment-card p,
.ticket-thread .ticket-detail-body,
.ticket-thread .comment-text { white-space: pre-wrap; word-break: break-word; }

/* Ticket description: the prominent anchor of the thread. Accent border +
   tinted background set it clearly apart from the comment cards below. */
.ticket-thread .ticket-detail-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
}
.ticket-thread .ticket-detail-label { color: var(--accent); }
.ticket-thread .ticket-detail-card .ticket-detail-body {
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text);
}
.ticket-thread .comment-avatar {
  width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--accent-soft);
  color: var(--text); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 32px;
}
.ticket-side .side-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; }
.ticket-side .side-card-header { padding: 9px 13px; border-bottom: 1px solid var(--border); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.05em; color: var(--text-muted); background: var(--bg-alt); }
.ticket-side .side-card-body { padding: 12px 13px; }
.prop-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 0.88rem; }
.prop-row .prop-key { color: var(--text-muted); }

/* ---- Custom searchable dropdown (select-issue) --------------------------- */
.dropdown { position: relative; display: inline-block; width: 100%; padding: 10px 0; }
.dropdown input { width: 100%; padding: 8px; box-sizing: border-box; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-surface); }
.dropdown-content { position: absolute; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 150px; overflow-y: auto; width: 100%; display: none; z-index: 999; box-shadow: var(--shadow-pop); }
.dropdown-content div { padding: 8px; cursor: pointer; }
.dropdown-content div:hover { background: var(--accent-soft); }
.other-input { margin-top: 10px; display: none; }
.other-input input { width: 100%; padding: 8px; box-sizing: border-box; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* Mobile sidebar overlay */
@media (max-width: 991.98px) {
  .app-sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s ease; width: 200px; flex-basis: 200px; }
  .app-shell.sidebar-open-mobile .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-open-mobile .app-sidebar .sidebar-label { opacity: 1; }
  .app-main { width: 100%; }
}

/* ---- Idle session timeout warning --------------------------------------- */
.idle-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1080;
}
.idle-modal.open { display: flex; }
.idle-modal-box {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  max-width: 360px;
  width: calc(100% - 2rem);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.idle-modal-box h5 { margin-bottom: 0.5rem; }
.idle-modal-box .idle-countdown { font-size: 0.95rem; color: var(--text-muted, #666); }
.idle-modal-box .idle-countdown strong { color: var(--accent); }
.idle-modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

/* ---- Ticket code links (ticket list) ------------------------------------ */
.ticket-code-link {
  font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.ticket-code-link:hover { text-decoration: underline; }

/* ---- Ticket activity log (ticketDetail history panel) ------------------- */
.activity-log { list-style: none; margin: 0; padding: 0; }
.activity-log li {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.activity-log li:last-child { border-bottom: none; }
.activity-log em { font-style: normal; font-weight: 600; color: var(--accent); }

/* ---- Attachments (ticket detail) ---------------------------------------- */
.attachment-list { list-style: none; margin: 0; padding: 0; }
.attachment-list li { padding: 3px 0; font-size: 0.85rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.attachment-list li a { color: var(--accent-strong); text-decoration: none; }
.attachment-list li a:hover { text-decoration: underline; }
.attachment-list .att-deleted { color: var(--text-muted); }
.att-del-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 0 2px; font-size: 0.8rem; line-height: 1;
}
.att-del-btn:hover { color: var(--st-red, #c0392b); }
