*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: #1a1a1a;
  background: #f5f5f3;
  line-height: 1.6;
}

.container { max-width: 800px; margin: 0 auto; padding: 0 1rem; }

/* Header */
.header {
  background: #fff;
  border-bottom: 1px solid #e5e5e2;
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header .container { display: flex; align-items: center; justify-content: space-between; }
.logo { font-size: 15px; font-weight: 600; }

#role-bar { display: flex; gap: 4px; background: #f1efe8; border-radius: 8px; padding: 3px; }
.role-btn {
  padding: 5px 14px; border: none; background: transparent; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: #666; cursor: pointer; transition: all .15s;
}
.role-btn.active { background: #fff; color: #1a1a1a; box-shadow: 0 0 0 0.5px #d3d1c7; }

/* Main */
main { padding: 2rem 1rem; }

/* Tabs */
.tab-bar { display: flex; border-bottom: 1px solid #e5e5e2; margin-bottom: 1.5rem; }
.tab {
  padding: 8px 16px; border: none; background: transparent; font-size: 13px; font-weight: 500;
  color: #888; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all .15s;
}
.tab:hover { color: #1a1a1a; }
.tab.active { color: #1a1a1a; border-bottom-color: #1a1a1a; }

/* Card */
.card { background: #fff; border: 1px solid #e5e5e2; border-radius: 12px; padding: 1.5rem; margin-bottom: 1rem; }
.card h2 { font-size: 16px; font-weight: 600; margin-bottom: 1rem; }

/* Form */
label { display: block; font-size: 13px; color: #555; margin-bottom: 4px; margin-top: 14px; }
label:first-of-type { margin-top: 0; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 7px;
  font-size: 14px; font-family: inherit; background: #fff; color: #1a1a1a; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #888; box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
textarea { min-height: 90px; resize: vertical; }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.form-actions { margin-top: 1.25rem; display: flex; justify-content: flex-end; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border: 1px solid #ddd; border-radius: 7px; font-size: 13px; font-weight: 500;
  background: #fff; color: #1a1a1a; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { background: #f5f5f3; border-color: #bbb; }
.btn.primary { background: #1a1a1a; color: #fff; border-color: transparent; }
.btn.primary:hover { background: #333; }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn.danger { background: #fff; color: #a32d2d; border-color: #f09595; }
.btn.danger:hover { background: #fcebeb; }

/* Messages */
.msg { padding: 10px 14px; border-radius: 7px; font-size: 13px; margin-bottom: 1rem; }
.msg.success { background: #eaf3de; color: #3b6d11; border: 1px solid #97c459; }
.msg.error   { background: #fcebeb; color: #a32d2d; border: 1px solid #f09595; }
.msg.info    { background: #e6f1fb; color: #185fa5; border: 1px solid #85b7eb; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
/* Status */
.badge.open        { background: #e6f1fb; color: #185fa5; }
.badge.in-progress { background: #faeeda; color: #854f0b; }
.badge.resolved    { background: #eaf3de; color: #3b6d11; }
.badge.closed      { background: #f1efe8; color: #5f5e5a; }

/* Priority */
.badge.pri-low    { background: #f5f5f3; color: #888; }
.badge.pri-normal { background: #e6f1fb; color: #185fa5; }
.badge.pri-high   { background: #faeeda; color: #854f0b; }
.badge.pri-urgent { background: #fcebeb; color: #a32d2d; }

/* Source */
.badge.source-badge        { background: #f1efe8; color: #5f5e5a; }
.badge.xelamour            { background: #f4ebf8; color: #7b2d8b; }
.badge.xelengine           { background: #e8f0fe; color: #1a56a8; }
.badge.refreshlearning     { background: #e3f4ea; color: #1a6e3c; }
.badge.direct              { background: #f5f5f3; color: #666; }
.badge.role-badge          { background: #fff3cd; color: #856404; }

/* Ticket detail */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; margin: 1rem 0 0; }
.detail-item { padding: 8px 0; border-bottom: 1px solid #f1efe8; }
.detail-item:nth-last-child(-n+2) { border-bottom: none; }
.detail-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.detail-value { font-size: 14px; color: #1a1a1a; }
.desc-box {
  background: #f7f7f5; border-radius: 7px; padding: 10px 12px;
  font-size: 13px; color: #444; margin-top: 6px; line-height: 1.6;
}
.desc-box ul, .desc-box ol { padding-left: 1.4em; margin: 4px 0; }
.desc-box p { margin: 2px 0; }

/* Staff panel */
.staff-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.staff-header h2 { font-size: 16px; font-weight: 600; }

.stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 1.5rem; }
.stat { background: #fff; border: 1px solid #e5e5e2; border-radius: 10px; padding: 12px; text-align: center; }
.stat-num { font-size: 20px; font-weight: 600; }
.stat-label { font-size: 11px; color: #888; margin-top: 2px; }

/* Filter bar */
.filter-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 1rem; padding: 10px 12px;
  background: #fff; border: 1px solid #e5e5e2; border-radius: 10px;
}
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.filter-group select { width: auto; font-size: 13px; padding: 5px 8px; }
.search-wrap { display: flex; align-items: center; }
.search-wrap input { font-size: 13px; padding: 5px 10px; min-width: 200px; }

/* Ticket list */
.ticket-list { background: #fff; border: 1px solid #e5e5e2; border-radius: 12px; overflow: hidden; }
.ticket-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid #f1efe8; cursor: pointer; transition: background .1s;
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: #f9f9f7; }
.ticket-row.active { background: #f0f0ee; }
.ticket-id { font-family: monospace; font-size: 12px; color: #888; min-width: 88px; }
.ticket-info { flex: 1; min-width: 0; }
.ticket-subject { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-meta { font-size: 12px; color: #888; margin-top: 2px; }
.source-tag { display: inline; font-size: 11px; font-weight: 600; }

/* Staff detail controls */
.detail-controls { margin-top: 1.25rem; }
.control-row { display: flex; gap: 12px; flex-wrap: wrap; }
.control-item { display: flex; flex-direction: column; }
.control-item select, .control-item input { width: auto; font-size: 13px; padding: 6px 8px; }
#ticket-detail { margin-top: 1rem; }
.detail-actions { display: flex; gap: 8px; align-items: center; margin-top: 1rem; flex-wrap: wrap; }

/* Work notes */
.work-notes-section { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid #e5e5e2; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #666; margin-bottom: 10px; }
.work-note {
  background: #fffbf0; border: 1px solid #efe8c4; border-radius: 7px;
  padding: 10px 12px; margin-bottom: 8px;
}
.work-note-meta { font-size: 12px; color: #888; margin-bottom: 4px; }
.work-note-text { font-size: 13px; color: #333; white-space: pre-wrap; }

/* Misc */
.empty { text-align: center; padding: 3rem 1rem; color: #888; font-size: 14px; }
.muted { color: #888; font-size: 13px; margin-bottom: 1rem; }

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .control-row { flex-direction: column; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-wrap input { min-width: unset; width: 100%; }
}
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Auth card */
.auth-card { max-width: 380px; margin: 2rem auto; text-align: center; }
.auth-card h2 { margin-bottom: 0.5rem; }
.auth-card .muted { margin-bottom: 1.5rem; }
.auth-logo { margin-bottom: 1rem; }

/* Google SSO button */
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  width: 100%;
  justify-content: center;
}
.btn-google:hover {
  background: #f8f8f6;
  border-color: #bbb;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
}

/* PIN fallback */
.pin-fallback { text-align: left; }

/* Staff identity in header */
.staff-identity { font-size: 12px; color: #888; margin-top: 2px; }
.staff-name  { font-weight: 500; color: #555; }
.staff-email { color: #aaa; }

/* SLA badges */
.badge.sla-ok     { background: #eaf3de; color: #3b6d11; }
.badge.sla-warn   { background: #faeeda; color: #854f0b; }
.badge.sla-breach { background: #fde8e8; color: #a32d2d; }

/* Role badges */
.badge.role-staff           { background: #e8ecfd; color: #2840b5; }
.badge.role-customer        { background: #f1efe8; color: #5f5e5a; }
.badge.role-support_agent   { background: #f5f5f3; color: #555; }
.badge.role-support_manager { background: #e6f1fb; color: #185fa5; }
.badge.role-admin           { background: #faeeda; color: #854f0b; }
.badge.role-superadmin      { background: #eaf3de; color: #3b6d11; }

/* Footer */
.footer {
  border-top: 1px solid #e5e5e2;
  padding: 18px 0;
  text-align: center;
  font-size: 12px;
  color: #bbb;
  margin-top: 3rem;
  background: #fff;
}
.footer a { color: #aaa; text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Admin section */
.admin-section { margin-top: 1rem; }
.admin-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-weight: 600;
  font-size: 15px;
  color: #1a1a1a;
}

/* Admin table rows */
.admin-table { display: flex; flex-direction: column; gap: 1px; }
.admin-row {
  background: #fff;
  border: 1px solid #e8e6de;
  border-radius: 6px;
  margin-bottom: 4px;
  overflow: hidden;
}
.admin-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.admin-row-name {
  font-weight: 500;
  font-size: 14px;
}
.admin-row-edit {
  padding: 12px 14px;
  background: #fafaf8;
  border-top: 1px solid #e8e6de;
}

/* Add form card inside admin sections */
#add-category-form,
#add-sla-form {
  background: #fafaf8;
  border: 1px solid #e8e6de;
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 12px;
}

/* Customer portal auth hero */
.customer-auth-hero {
  max-width: 420px;
  margin: 3rem auto;
}

/* -------------------------------------------------------------------------
   Rich text editor
   ---------------------------------------------------------------------- */
.editor-wrap {
  border: 1px solid #ddd;
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}
.editor-wrap:focus-within { border-color: #888; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  background: #fafaf8;
  border-bottom: 1px solid #e8e6de;
  flex-wrap: wrap;
}
.editor-toolbar button {
  width: 28px; height: 28px;
  border: none; border-radius: 5px;
  background: transparent; cursor: pointer;
  font-size: 13px; color: #444;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.editor-toolbar button:hover { background: #efefed; }
.tb-sep { width: 1px; height: 18px; background: #ddd; margin: 0 3px; }

.rich-editor {
  min-height: 90px;
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
  color: #1a1a1a;
}
.rich-editor.editor-empty::before {
  content: attr(data-placeholder);
  color: #aaa;
  pointer-events: none;
}
.rich-editor ul, .rich-editor ol { padding-left: 1.4em; margin: 4px 0; }
.rich-editor p { margin: 2px 0; }

/* -------------------------------------------------------------------------
   Drop zone
   ---------------------------------------------------------------------- */
.drop-zone {
  border: 1.5px dashed #d3d1c7;
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
  background: #fafaf8;
  transition: border-color .15s, background .15s;
  font-size: 13px;
  color: #666;
}
.drop-zone.drag-over { border-color: #888; background: #f1efe8; }
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dz-inner svg { margin-bottom: 2px; }
.dz-browse { color: #185fa5; cursor: pointer; text-decoration: underline; margin-left: 3px; }
.dz-files  { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; justify-content: center; }
.dz-file-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border: 1px solid #ddd; border-radius: 20px;
  padding: 3px 8px 3px 10px; font-size: 12px; color: #444;
}
.dz-chip-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dz-chip-size { color: #aaa; font-size: 11px; }
.dz-chip-remove {
  border: none; background: none; cursor: pointer;
  font-size: 14px; color: #aaa; padding: 0 1px; line-height: 1;
}
.dz-chip-remove:hover { color: #a32d2d; }

/* -------------------------------------------------------------------------
   Reply thread
   ---------------------------------------------------------------------- */
.reply-thread {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thread-title {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: #666; margin-bottom: 4px;
}
.reply-item {
  background: #fff;
  border: 1px solid #e5e5e2;
  border-radius: 10px;
  padding: 12px 14px;
}
.reply-item.reply-staff    { border-left: 3px solid #185fa5; }
.reply-item.reply-customer { border-left: 3px solid #3b6d11; }
.reply-item.reply-internal { background: #fffbf0; border-color: #efe8c4; border-left: 3px solid #c9a53d; }

.reply-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: #888; margin-bottom: 8px; flex-wrap: wrap;
}
.reply-author { font-weight: 600; color: #444; }
.reply-body   { font-size: 14px; line-height: 1.6; }
.reply-body img     { max-width: 100%; border-radius: 4px; }
.reply-body ul, .reply-body ol { padding-left: 1.4em; margin: 4px 0; }
.reply-body p  { margin: 2px 0; }

.attachment-list { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-item {
  display: inline-flex; align-items: center; gap: 5px;
  background: #f5f5f3; border: 1px solid #e5e5e2; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; color: #444;
  text-decoration: none; transition: background .1s;
}
.attachment-item:hover { background: #ebebea; }

/* Reply compose area */
.reply-compose {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5e5e2;
}
.compose-title {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  color: #666; margin-bottom: 10px;
}
.compose-options {
  display: flex; align-items: center; gap: 12px;
  margin-top: 10px; flex-wrap: wrap;
}
.compose-options label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: #555; }
.compose-options input[type=checkbox] { width: auto; }
.compose-actions {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; flex-wrap: wrap;
}

/* Success / error message boxes */
.msg.success {
  background: #eaf3de;
  color: #3b6d11;
  border: 1px solid #c3dfa3;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}
.msg.error {
  background: #fde8e8;
  color: #a32d2d;
  border: 1px solid #f5b8b8;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}
.msg.info {
  background: #e6f1fb;
  color: #185fa5;
  border: 1px solid #b3d4f5;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 12px;
}
