@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Montserrat:wght@400;500;600&display=swap");

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Montserrat", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(135deg, rgba(198, 167, 93, 0.14), transparent 40%),
    radial-gradient(circle at 20% 0%, rgba(31, 63, 102, 0.08), transparent 50%),
    var(--paper);
}

body::after {
  content: "TicketGal 0.9.0";
  position: absolute;
  left: 0.75rem;
  bottom: 0.25rem;
  white-space: nowrap;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: rgba(25, 36, 50, 0.45);
  z-index: 20;
  pointer-events: none;
  user-select: none;
}

.app-footer {
  margin-top: auto;
  text-align: center;
  padding: 1.2rem 1rem 1.8rem;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.app-footer-help {
  display: grid;
  gap: 0.18rem;
  margin-bottom: 0.5rem;
}

#footer-help-email {
  color: var(--navy-700);
  text-decoration: underline;
}

#footer-help-email:hover {
  color: var(--navy-900);
}

#footer-copyright {
  margin: 0;
}

.brand-strip {
  background: var(--navy-900);
  color: #e6edf8;
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.brand-strip-slot {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
}

.brand-strip-slot-image {
  letter-spacing: normal;
  text-transform: none;
}

.brand-strip-logo {
  display: block;
  max-height: 34px;
  width: auto;
  max-width: min(40vw, 240px);
  object-fit: contain;
}

.brand-strip-has-image {
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

.brand-strip .dot {
  color: var(--gold-400);
  margin: 0 0.5rem;
}

.shell {
  width: min(1120px, 92vw);
  margin: 1.4rem auto 3rem;
  display: grid;
  gap: 1rem;
}

body.user-portal-shell .shell,
.shell.user-mode {
  width: 60vw;
}

.shell.admin-mode {
  width: 98vw;
}

.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
}

.admin-content {
  min-width: 0;
}

.admin-sidenav {
  display: grid;
  gap: 0.55rem;
  align-content: start;
  height: fit-content;
  position: sticky;
  top: 1rem;
}

.nav-btn {
  text-align: left;
  background: #f4efe2;
  color: #22344a;
  border: 1px solid #e0d4b8;
}

.nav-btn.active {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-500));
  border-color: #b7934a;
  color: #17212f;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-500);
  font-weight: 600;
}

.eyebrow.light {
  color: var(--gold-400);
}

.auth-shell h1,
.hero h1,
h2,
h3 {
  font-family: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  letter-spacing: 0.02em;
}

.auth-shell h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: clamp(2rem, 3.8vw, 2.8rem);
}

.auth-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.auth-single {
  display: grid;
  grid-template-columns: minmax(0, 420px);
  justify-content: center;
  margin-top: 1rem;
}

.register-link {
  margin-top: 0.4rem;
  font-size: 0.875rem;
}

.register-link a {
  color: var(--navy-700);
  font-weight: 600;
  text-decoration: underline;
}

.register-link a:hover {
  color: var(--navy-900);
}

.card {
  background: linear-gradient(180deg, #fffefb, var(--card));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.auth-card {
  display: grid;
  gap: 0.65rem;
}

.auth-alt {
  display: grid;
  gap: 0.65rem;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, #d8cfbc, transparent);
}

.microsoft-login-btn {
  background: linear-gradient(180deg, #f8fafc, #e8eef5);
  color: #132235;
  border: 1px solid #c7d4e3;
}

.microsoft-login-btn:hover {
  background: linear-gradient(180deg, #ffffff, #dee8f3);
}

.auth-note {
  margin-top: -0.2rem;
  font-size: 0.82rem;
}

.card-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--navy-700);
  font-size: 0.72rem;
  font-weight: 600;
}

.hero {
  background:
    linear-gradient(120deg, rgba(13, 29, 48, 0.95), rgba(20, 42, 69, 0.92)),
    linear-gradient(130deg, rgba(198, 167, 93, 0.16), transparent 50%);
  color: #f8fbff;
  border-radius: 16px;
  padding: 1.2rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid rgba(216, 187, 121, 0.25);
}

.hero h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.75rem, 3vw, 2.4rem);
}

.hero p {
  margin: 0.35rem 0 0;
}

#app-view:not(.hidden) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

#app-view.alerts-enabled:not(.hidden) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
  align-items: start;
}

#app-view > .hero {
  grid-column: 1 / -1;
}

#user-shell,
#admin-shell {
  grid-column: 1;
}

#alerts-feed {
  display: none;
}

#app-view.alerts-enabled #alerts-feed {
  display: block;
  grid-column: 2;
  grid-row: 2;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

.alerts-list {
  display: grid;
  gap: 0.55rem;
}

.alert-item {
  border: 1px solid #e2d8c3;
  border-radius: 10px;
  background: #fff;
  padding: 0.6rem;
  display: grid;
  gap: 0.35rem;
}

.alert-item h3 {
  margin: 0;
  font-size: 1rem;
}

.alert-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.alert-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
}

.alert-dismiss-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}

.alert-create-ticket-btn {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}

.alert-severity {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: 999px;
  width: fit-content;
  padding: 0.14rem 0.45rem;
  border: 1px solid #d7ccb3;
  background: #f5efe1;
  color: #3e3a31;
}

.alert-severity-critical,
.alert-severity-high {
  border-color: #e7b9b6;
  background: #fae8e7;
  color: #9a2d25;
}

.alert-severity-warning,
.alert-severity-medium {
  border-color: #e7d1a4;
  background: #f9f2e1;
  color: #8a6223;
}

.alert-severity-low,
.alert-severity-info {
  border-color: #bdd4e6;
  background: #eaf3fb;
  color: #27507f;
}

.drop-zone {
  border: 1px dashed var(--gold-500);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  background: linear-gradient(180deg, #fffcf5, #f8f1e1);
  color: var(--navy-700);
  margin-bottom: 0.45rem;
  transition: background 120ms ease, transform 120ms ease, border-color 120ms ease;
}

.drop-zone.dragover {
  background: linear-gradient(180deg, #fff8e8, #f4e5bf);
  transform: translateY(-2px);
  border-color: #9f7b2d;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.span-2 {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: #263445;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  border: 1px solid #ccbfa3;
  border-radius: 8px;
  padding: 0.56rem 0.62rem;
  background: #fff;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(198, 167, 93, 0.35);
  outline-offset: 1px;
}

input.readonly {
  background: #f5f4f2;
}

button {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-500));
  border: 0;
  color: #1a2431;
  border-radius: 8px;
  padding: 0.56rem 0.92rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  filter: brightness(0.97);
}

.ticket-open-btn {
  background: transparent;
  color: var(--navy-700);
  padding: 0;
  border: 0;
  border-radius: 0;
  text-align: left;
  text-decoration: underline;
  font-weight: 600;
}

.ticket-open-btn:hover {
  filter: none;
  color: var(--navy-900);
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.status-filter-checks {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-filter-checks label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
}

.ticket-search-field {
  display: grid;
  gap: 0.25rem;
  min-width: min(360px, 100%);
}

.ticket-search-field span {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--navy-700);
}

.ticket-search-field input {
  min-width: min(360px, 100%);
}

.report-custom-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.65rem;
  margin: 0.5rem 0 0.75rem;
}

.report-custom-controls label {
  display: grid;
  gap: 0.25rem;
  min-width: 170px;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.list-header h2 {
  margin: 0;
}

.page-header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.page-header-actions h2 {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.7rem;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid #e4dcc9;
  padding: 0.56rem 0.45rem;
  vertical-align: top;
}

th {
  background: #f0e8d5;
  font-weight: 600;
  color: #213247;
}

td input,
td select {
  width: 100%;
}

.status-wrap {
  display: grid;
  gap: 0.35rem;
}

.status-open {
  color: #c62828;
}

.status-pending {
  color: #b8860b;
}

.status-resolved {
  color: #2e7d32;
}

.status-closed {
  color: #d81b60;
}

.status-queued {
  color: #6a5acd;
  font-style: italic;
}

.queued-badge {
  color: #6a5acd;
  font-size: 0.82em;
  font-style: italic;
}

.history-entry-queued {
  border-color: #c8bfe8;
  background: #f5f2ff;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.pending-row {
  display: grid;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  border: 1px solid #e2d8c3;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.55rem;
  background: #fffdf9;
}

.user-account-summary {
  display: grid;
  gap: 0.2rem;
  min-width: 240px;
  flex: 1 1 260px;
}

.user-account-title {
  font-weight: 600;
  color: var(--ink);
}

.user-account-meta {
  font-size: 0.82rem;
  color: var(--muted);
}

.user-account-audit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.2rem;
}

.user-account-audit-actions button {
  padding: 0.38rem 0.62rem;
  font-size: 0.8rem;
}

.audit-detail-stack {
  display: grid;
  gap: 0.12rem;
}

.audit-detail-primary {
  color: var(--ink);
  font-weight: 500;
}

.audit-detail-secondary {
  color: var(--muted);
  font-size: 0.82rem;
}

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

.ticket-viewer {
  position: fixed;
  inset: 0;
  background: rgba(10, 19, 33, 0.58);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}

.ticket-viewer.hidden {
  display: none;
}

body.ticket-viewer-standalone .brand-strip,
body.ticket-viewer-standalone .hero,
body.ticket-viewer-standalone #alerts-feed,
body.ticket-viewer-standalone #user-shell,
body.ticket-viewer-standalone #admin-shell,
body.ticket-viewer-standalone #auth-view {
  display: none !important;
}

body.ticket-viewer-standalone .shell {
  width: min(1380px, 98vw);
  margin: 0 auto;
  display: block;
}

body.ticket-viewer-standalone #app-view {
  display: block !important;
}

body.ticket-viewer-standalone #ticket-viewer {
  position: static;
  inset: auto;
  background: transparent;
  display: block;
  padding: 0;
}

body.ticket-viewer-standalone #ticket-viewer.hidden {
  display: block !important;
}

body.ticket-viewer-standalone #ticket-viewer .ticket-viewer-panel {
  width: 100%;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
  border: 0;
  padding: 0.8rem 0.4rem 1rem;
}

.ticket-viewer-panel {
  width: min(1320px, 97vw);
  max-height: 85vh;
  overflow: auto;
  background: #fffefb;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 34px rgba(6, 15, 28, 0.35);
  padding: 1rem;
}

.create-ticket-modal-panel {
  width: min(1470px, 97vw);
}

.ticket-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ticket-viewer-meta {
  border: 1px solid #e4dcc9;
  border-radius: 10px;
  background: #f8f3e6;
  padding: 0.65rem;
  margin-bottom: 0.7rem;
}

.ticket-viewer-update {
  border: 1px solid #e4dcc9;
  border-radius: 10px;
  background: #fff;
  padding: 0.7rem;
  margin-bottom: 0.7rem;
}

.ticket-viewer-update h3 {
  margin: 0 0 0.5rem;
}

.viewer-update-form {
  display: grid;
  gap: 0.5rem;
}

.checkbox-inline-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: fit-content;
}

.checkbox-inline-label input[type="checkbox"] {
  margin: 0;
}

.ticket-viewer-history {
  display: grid;
  gap: 0.55rem;
}

.history-entry {
  border: 1px solid #e2d8c3;
  border-radius: 10px;
  padding: 0.6rem;
  background: #fff;
}

.history-comment {
  margin-top: 0.45rem;
  line-height: 1.45;
  word-break: break-word;
}

.history-comment p,
.history-comment div {
  margin: 0.25rem 0 0.55rem;
}

.history-comment h1,
.history-comment h2,
.history-comment h3,
.history-comment h4,
.history-comment h5,
.history-comment h6 {
  margin: 0.35rem 0 0.55rem;
  line-height: 1.25;
}

.history-comment ul,
.history-comment ol {
  margin: 0.35rem 0 0.6rem 1.25rem;
  padding: 0;
}

.history-comment li {
  margin: 0.15rem 0;
}

.history-comment pre {
  margin: 0.4rem 0 0.6rem;
  padding: 0.5rem;
  border: 1px solid #e4dcc9;
  border-radius: 8px;
  background: #f6f3ea;
  overflow: auto;
}

.history-comment code {
  font-family: Consolas, Monaco, monospace;
  font-size: 0.86em;
}

.history-comment a {
  color: #1f3f66;
  text-decoration: underline;
}

.history-comment hr {
  border: 0;
  border-top: 1px solid #e2d8c3;
  margin: 0.65rem 0;
}

.history-comment img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 0.4rem 0;
}

@media (max-width: 860px) {
  .brand-strip {
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .brand-strip-logo {
    max-height: 30px;
    max-width: min(70vw, 220px);
  }

  .ticket-search-field,
  .ticket-search-field input {
    min-width: 100%;
  }

  .page-header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  #app-view:not(.hidden) {
    grid-template-columns: 1fr;
  }

  #alerts-feed {
    grid-column: 1;
    grid-row: auto;
    position: static;
    max-height: none;
  }

  .shell.admin-mode {
    width: 96vw;
  }

  body.user-portal-shell .shell,
  .shell.user-mode {
    width: 94vw;
  }

  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-sidenav {
    position: static;
  }

  .auth-panels,
  .auth-single,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .pending-row {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  table,
  thead,
  tbody,
  .status-resolved {
    color: #2e7d32;
  }

  .status-closed {
    color: #d81b60;
  }

  tr {
    border: 1px solid #e4dcc9;
    border-radius: 10px;
    margin-bottom: 0.8rem;
    padding: 0.4rem;
    background: #fff;
  }

  td {
    border: 0;
    padding: 0.35rem;
  }
}

/* ── Premium Admin Theme (rose / blush palette from bg.jpg) ── */

body.theme-premium {
  background: linear-gradient(135deg, #2d1520 0%, #3d1f2a 40%, #5c2e3e 100%) !important;
  background-attachment: fixed !important;
}

body.theme-premium::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url("/static/bg.jpg");
  background-size: cover;
  background-position: center;
  opacity: 0.22;
  z-index: -1;
  pointer-events: none;
}

body.theme-premium .brand-strip {
  background: #2d1520;
  color: #f0d0d0;
}

body.theme-premium .brand-strip .dot {
  color: #d4a0a8;
}

body.theme-premium .shell {
  margin-top: 0.5rem;
}

body.theme-premium .card {
  background: rgba(255, 250, 251, 0.96);
  border-color: #e0c0c4;
  box-shadow: 0 8px 32px rgba(45, 21, 32, 0.3);
}

body.theme-premium .card-kicker {
  color: #5c2e3e;
  font-weight: 700;
}

body.theme-premium .hero {
  background: linear-gradient(120deg, rgba(45, 21, 32, 0.97), rgba(92, 46, 62, 0.94)) !important;
  border-color: rgba(212, 160, 168, 0.35) !important;
  box-shadow: 0 8px 32px rgba(45, 21, 32, 0.4);
}

body.theme-premium .hero h1 {
  color: #f0d0d0;
}

body.theme-premium .hero .eyebrow {
  color: #d4a0a8;
}

body.theme-premium .hero p {
  color: #c8a0a6;
}

body.theme-premium label {
  color: #3d1f2a;
}

body.theme-premium input,
body.theme-premium textarea,
body.theme-premium select {
  border-color: #d4b8bc;
}

body.theme-premium input:focus,
body.theme-premium textarea:focus,
body.theme-premium select:focus {
  outline-color: rgba(196, 154, 158, 0.5);
}

body.theme-premium button:not(.ticket-open-btn) {
  background: linear-gradient(180deg, #d4a0a8, #c49a9e);
  color: #2d1520;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(196, 154, 158, 0.35);
}

body.theme-premium button:not(.ticket-open-btn):hover {
  filter: brightness(0.95);
  box-shadow: 0 6px 16px rgba(196, 154, 158, 0.45);
}

body.theme-premium .ticket-open-btn {
  color: #5c2e3e;
}

body.theme-premium .ticket-open-btn:hover {
  color: #2d1520;
}

body.theme-premium .nav-btn.active {
  background: linear-gradient(180deg, #d4a0a8, #c49a9e);
  color: #2d1520;
  border-color: #b08088;
  box-shadow: 0 4px 12px rgba(196, 154, 158, 0.35);
}

body.theme-premium .nav-btn {
  background: rgba(255, 245, 247, 0.92);
  color: #3d1f2a;
  border-color: #d4a0a8;
}

body.theme-premium .nav-btn:hover {
  background: rgba(240, 208, 208, 0.95);
}

body.theme-premium .admin-sidenav {
  border: 2px solid #d4a0a8;
  border-radius: 14px;
  padding: 0.6rem;
  background: rgba(255, 250, 251, 0.96);
  box-shadow: 0 8px 32px rgba(45, 21, 32, 0.25);
}

body.theme-premium th {
  background: #f0d0d0;
  color: #3d1f2a;
}

body.theme-premium td {
  border-color: #e8c8cc;
}

body.theme-premium table {
  border: 1px solid #e0c0c4;
}

body.theme-premium .drop-zone {
  border-color: #d4a0a8;
  background: linear-gradient(180deg, #fff5f7, #f4e0e3);
  color: #5c2e3e;
}

body.theme-premium .drop-zone.dragover {
  background: linear-gradient(180deg, #ffeef0, #f0ccd2);
  border-color: #b08088;
}

body.theme-premium .eyebrow {
  color: #c49a9e;
}

body.theme-premium .pending-row {
  border-color: #e0c0c4;
  background: #fff8f9;
}

body.theme-premium .user-account-title,
body.theme-premium .audit-detail-primary {
  color: #3d1f2a;
}

body.theme-premium .user-account-meta,
body.theme-premium .audit-detail-secondary {
  color: #7b5760;
}

body.theme-premium .ticket-viewer {
  background: rgba(45, 21, 32, 0.6);
}

body.theme-premium .ticket-viewer-panel {
  border-color: #d4a0a8;
  box-shadow: 0 18px 40px rgba(45, 21, 32, 0.45);
}

body.theme-premium .ticket-viewer-meta {
  background: #f8e8ea;
  border-color: #e0c0c4;
}

body.theme-premium .ticket-viewer-update {
  border-color: #e0c0c4;
}

body.theme-premium .history-entry {
  border-color: #e0c0c4;
}

body.theme-premium .history-comment pre {
  border-color: #e0c0c4;
  background: #f8e8ea;
}

body.theme-premium .history-comment a {
  color: #5c2e3e;
}

body.theme-premium .history-comment hr {
  border-top-color: #e0c0c4;
}

body.theme-premium .register-link a {
  color: #5c2e3e;
}

body.theme-premium .register-link a:hover {
  color: #2d1520;
}

.settings-section {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e0d4b8;
}

.user-search-bar {
  margin-bottom: 1rem;
}

.user-search-bar input[type="search"] {
  width: 100%;
  max-width: 360px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccbfa3;
  border-radius: 8px;
  font-size: 0.9rem;
}

body.theme-premium .user-search-bar input[type="search"] {
  border-color: #d4a0a8;
  background: #fff8f9;
}

.lockout-controls {
  justify-content: flex-start;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.lockout-controls input,
.lockout-controls select {
  min-height: 38px;
}

#lockout-key-value {
  min-width: 240px;
  flex: 1 1 280px;
}

#lockout-list h4 {
  margin: 0.6rem 0 0.35rem;
}

.settings-section h3 {
  margin-top: 0;
  color: #1f3f66;
  font-weight: 700;
}

.theme-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-weight: 500;
  color: #192432;
  margin: 0.5rem 0;
}

.theme-toggle-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: #c49a9e;
}

.report-ai-summary,
.report-ai-error {
  white-space: pre-line;
  line-height: 1.55;
  border: 1px solid #e4dcc9;
  border-radius: 10px;
  background: #fff;
  padding: 0.8rem;
}

.report-ai-loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.report-fast-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  border: 1px solid #d8cfbc;
  border-radius: 999px;
  background: #fffaf0;
  padding: 0.6rem 0.95rem;
  box-shadow: 0 6px 16px rgba(26, 24, 18, 0.06);
}

.report-fast-mode-toggle input {
  width: 16px;
  height: 16px;
}

.report-options-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.85rem 0 0.45rem;
}

.report-fast-mode-title {
  font-weight: 700;
  color: var(--navy-900);
}

.report-fast-mode-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
}

.report-ai-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #d9cfba;
  border-top-color: #8f7440;
  border-radius: 50%;
  animation: report-spin 0.85s linear infinite;
}

@keyframes report-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.ai-ticket-link {
  border: 0;
  background: transparent;
  color: var(--navy-700);
  text-decoration: underline;
  padding: 0;
  margin: 0;
  font-weight: 700;
  cursor: pointer;
}

.ai-ticket-link:hover {
  color: var(--navy-900);
  filter: none;
}

.ai-ticket-link:focus-visible {
  outline: 2px solid rgba(198, 167, 93, 0.45);
  outline-offset: 2px;
  border-radius: 2px;
}

.report-ai-error {
  border-color: #e7b9b6;
  background: #fae8e7;
  color: #8b2e2b;
}

body.theme-premium .report-ai-summary {
  border-color: #e0c0c4;
  background: #fff8f9;
  color: #3d1f2a;
}

body.theme-premium .report-ai-loading {
  color: #7b5760;
}

body.theme-premium .report-ai-spinner {
  border-color: #e0c0c4;
  border-top-color: #9d6674;
}

body.theme-premium .ai-ticket-link {
  color: #5c2e3e;
}

body.theme-premium .ai-ticket-link:hover {
  color: #2d1520;
}

body.theme-premium .report-ai-error {
  border-color: #d88f95;
  background: #f9e6e8;
  color: #7f2a30;
}

/* ─── Audit-log modal ─── */

.audit-log-panel {
  width: min(1590px, 97vw);
}

.audit-log-filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.75rem;
}

.audit-log-filters input[type="search"] {
  flex: 1 1 260px;
  min-height: 36px;
}

.audit-log-filters select {
  min-height: 36px;
}

.audit-log-table-wrap {
  overflow-x: auto;
}

.audit-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.audit-log-table th,
.audit-log-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid #e8e0cf;
  vertical-align: top;
}

.audit-log-table th {
  background: #f3ede0;
  color: #2a3d5a;
  font-weight: 700;
  white-space: nowrap;
}

.audit-log-table tr:hover td {
  background: #faf7f0;
}

.audit-col-time {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.82rem;
}

.audit-col-meta {
  color: var(--muted);
  font-size: 0.82rem;
  word-break: break-all;
  max-width: 260px;
}

.audit-action-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  background: #e8f0fb;
  color: #1a3760;
}

.audit-action-auth {
  background: #e6f4ea;
  color: #1a5c30;
}

.audit-action-admin {
  background: #fdf3e0;
  color: #6b3d00;
}

.audit-action-allowed {
  background: #e6f4ea;
  color: #1a5c30;
}

.audit-action-denied {
  background: #fdecea;
  color: #8f1d1d;
}

.audit-log-pagination {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

#audit-log-page-info,
#kb-access-log-page-info {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.87rem;
}

/* ─── Knowledgebase modal ─── */

.kb-modal-panel {
  width: min(1350px, 97vw);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.kb-controls {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
  flex-wrap: wrap;
}

.kb-search-box {
  display: flex;
  gap: 0.4rem;
  flex: 1 1 240px;
  min-width: 200px;
}

.kb-search-box input {
  flex: 1;
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccbfa3;
  border-radius: 6px;
  font-size: 0.9rem;
}

.kb-search-box button {
  min-width: 80px;
  min-height: 36px;
}

#kb-new-article-btn {
  min-height: 36px;
  padding: 0.5rem 1rem;
  background: linear-gradient(180deg, var(--gold-400), var(--gold-500));
  border: 1px solid #b7934a;
  color: #17212f;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

#kb-new-article-btn:hover {
  opacity: 0.9;
}

.kb-content {
  display: flex;
  gap: 1rem;
  overflow: hidden;
  flex: 1;
  min-height: 300px;
}

.kb-articles-list {
  flex: 0 0 280px;
  overflow-y: auto;
  border: 1px solid #e8e0cf;
  border-radius: 6px;
  background: #faf7f0;
  padding: 0.75rem;
}

.kb-article-item {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid #ddd4c1;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  word-break: break-word;
}

.kb-article-item:hover {
  border-color: #c6a75d;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.kb-article-item.active {
  background: linear-gradient(180deg, rgba(198, 167, 93, 0.1), transparent);
  border-color: var(--gold-500);
}

.kb-article-title {
  font-weight: 600;
  color: #192432;
  font-size: 0.9rem;
  margin: 0 0 0.25rem;
}

.kb-article-badge {
  display: inline-block;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #e8f0fb;
  color: #1a3760;
  margin-top: 0.35rem;
}

.kb-badge-public {
  background: #e6f4ea;
  color: #1a5c30;
}

.kb-badge-admin {
  background: #fdf3e0;
  color: #6b3d00;
}

.kb-badge-company {
  background: #f3e8ff;
  color: #5e2270;
}

.kb-article-viewer {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  border: 1px solid #e8e0cf;
  border-radius: 6px;
  background: #fff;
}

.kb-article-viewer.hidden {
  display: none;
}

.kb-article-viewer h1,
.kb-article-viewer h2 {
  color: #1f3f66;
  margin-top: 1.2rem;
}

.kb-article-viewer h1:first-child,
.kb-article-viewer h2:first-child {
  margin-top: 0;
}

.kb-article-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e8e0cf;
}

.kb-article-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.kb-article-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.kb-article-actions button {
  min-height: 32px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid #ccbfa3;
  border-radius: 4px;
  background: #f4efe2;
  cursor: pointer;
  transition: all 0.2s ease;
}

.kb-article-actions button:hover {
  border-color: #b7934a;
  background: #ede5d0;
}

.kb-article-actions .btn-danger {
  border-color: #d4a4a4;
  background: #f7e7e6;
  color: #8b2e2b;
}

.kb-article-actions .btn-danger:hover {
  border-color: #c97a73;
  background: #f0d4d0;
}

.kb-article-content {
  line-height: 1.7;
  color: #192432;
}

.kb-article-content p {
  margin: 0.8rem 0;
}

.kb-article-content code {
  background: #f3ede0;
  padding: 0.2em 0.4em;
  border-radius: 3px;
  font-family: "Courier New", monospace;
  font-size: 0.9em;
}

.kb-article-content pre {
  background: #f3ede0;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  border: 1px solid #e8e0cf;
}

.kb-article-content blockquote {
  border-left: 4px solid var(--gold-500);
  padding-left: 1rem;
  margin-left: 0;
  color: var(--muted);
  font-style: italic;
}

.kb-article-content ul,
.kb-article-content ol {
  margin: 0.8rem 0;
  padding-left: 2rem;
}

.kb-article-content li {
  margin: 0.4rem 0;
}

.kb-article-content a {
  color: #1f3f66;
  text-decoration: underline;
}

.kb-article-content a:hover {
  color: #0e1c2f;
}

/* ─── Knowledgebase editor modal ─── */

.kb-editor-panel {
  width: min(900px, 96vw);
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.kb-editor-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.kb-editor-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 500;
  color: #192432;
}

.kb-editor-form input[type="text"],
.kb-editor-form input[type="email"],
.kb-editor-form select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccbfa3;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  color: #192432;
  background: #fff;
}

.kb-editor-form select option,
.kb-editor-form select optgroup {
  color: #192432;
  background: #fff;
}

.kb-editor-form input[type="text"]:focus,
.kb-editor-form input[type="email"]:focus,
.kb-editor-form select:focus {
  outline: 2px solid rgba(198, 167, 93, 0.5);
  outline-offset: 2px;
  border-color: var(--gold-500);
}

#kb-editor-codemirror {
  border: 1px solid #ccbfa3;
  border-radius: 6px;
  min-height: 300px;
  background: #fff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

#kb-editor-codemirror.dragover {
  border-color: var(--gold-500);
  background: #fff9ea;
  box-shadow: 0 0 0 3px rgba(198, 167, 93, 0.18);
}

.kb-editor-upload-hint {
  margin: -0.35rem 0 0;
  font-size: 0.85rem;
}

.cm-editor {
  font-family: "Courier New", Monaco, monospace;
  font-size: 0.9rem;
  height: 100%;
}

#kb-editor-codemirror .CodeMirror {
  font-family: "Courier New", Monaco, monospace;
  font-size: 0.9rem;
  min-height: 320px;
  height: auto;
  background: transparent;
}

#kb-editor-codemirror .CodeMirror-scroll {
  min-height: 320px;
}

.kb-editor-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding-top: 0.75rem;
  border-top: 1px solid #e8e0cf;
  margin-top: 0.75rem;
}

.kb-editor-actions button {
  min-height: 36px;
  padding: 0.5rem 1.2rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

#kb-editor-save {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-500));
  border: 1px solid #b7934a;
  color: #17212f;
}

#kb-editor-save:hover {
  opacity: 0.9;
}

#kb-editor-cancel {
  background: #f4efe2;
  border: 1px solid #ccbfa3;
  color: #192432;
}

#kb-editor-cancel:hover {
  background: #ede5d0;
  border-color: #b7934a;
}

#kb-editor-delete {
  background: #f7e7e6;
  border: 1px solid #d4a4a4;
  color: #8b2e2b;
}

#kb-editor-delete:hover {
  background: #f0d4d0;
  border-color: #c97a73;
}

#kb-editor-status {
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--muted);
}

/* ─── Premium theme KB styles ─── */

body.theme-premium .kb-search-box input {
  border-color: #d4a0a8;
  background: #fff8f9;
}

body.theme-premium #kb-new-article-btn {
  background: linear-gradient(180deg, #cc9ba5, #b97a8a);
  border-color: #9d6674;
  color: #fff;
}

body.theme-premium .kb-article-item {
  border-color: #e0c0c4;
  background: #fffbfc;
}

body.theme-premium .kb-article-item:hover {
  border-color: #c49a9e;
}

body.theme-premium .kb-article-item.active {
  background: linear-gradient(180deg, rgba(196, 154, 158, 0.1), transparent);
  border-color: #c49a9e;
}

body.theme-premium .kb-article-viewer {
  border-color: #e0c0c4;
  background: #fffbfc;
}

body.theme-premium .kb-article-header {
  border-bottom-color: #e0c0c4;
}

body.theme-premium .kb-editor-form input[type="text"],
body.theme-premium .kb-editor-form input[type="email"],
body.theme-premium .kb-editor-form select {
  border-color: #d4a0a8;
  background: #fff8f9;
  color: #3d1f2a;
}

body.theme-premium .kb-editor-form select option,
body.theme-premium .kb-editor-form select optgroup {
  color: #3d1f2a;
  background: #fff8f9;
}

body.theme-premium #kb-editor-codemirror {
  border-color: #d4a0a8;
  background: #fffbfc;
}

body.theme-premium #kb-editor-codemirror.dragover {
  border-color: #c49a9e;
  background: #fff2f5;
  box-shadow: 0 0 0 3px rgba(196, 154, 158, 0.18);
}

.kb-editor-standalone-body {
  margin: 0;
  padding: 1vh 1vw;
  min-height: 100vh;
}

.kb-editor-standalone-shell {
  width: 98vw;
  max-width: none;
  height: 98vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kb-editor-standalone-shell .kb-editor-form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.kb-editor-standalone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.kb-window-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.kb-window-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.kb-window-pane > label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
  min-height: 0;
}

.kb-window-preview-pane {
  border: 1px solid #e8e0cf;
  border-radius: 8px;
  background: #fffefb;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.kb-window-preview {
  min-height: 0;
  max-height: none;
  flex: 1;
  overflow: auto;
  border-top: 1px solid #e8e0cf;
  padding-top: 0.65rem;
}

.kb-window-preview h1,
.kb-window-preview h2,
.kb-window-preview h3,
.kb-window-preview h4,
.kb-window-preview h5,
.kb-window-preview h6 {
  margin: 0.45rem 0;
  color: #0e1c2f;
}

.kb-window-preview p,
.kb-window-preview ul,
.kb-window-preview ol,
.kb-window-preview pre,
.kb-window-preview blockquote {
  margin: 0.55rem 0;
}

.kb-window-preview img {
  max-width: 100%;
  border-radius: 6px;
}

.kb-window-preview a {
  color: #1f3f66;
}

#kb-window-editor-host {
  border: 1px solid #ccbfa3;
  border-radius: 6px;
  min-height: 0;
  height: 100%;
  flex: 1;
  background: #fff;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

#kb-window-editor-host.dragover {
  border-color: var(--gold-500);
  background: #fff9ea;
  box-shadow: 0 0 0 3px rgba(198, 167, 93, 0.18);
}

#kb-window-editor-host .CodeMirror {
  font-family: "Courier New", Monaco, monospace;
  font-size: 0.9rem;
  min-height: 0;
  height: 100%;
}

#kb-window-editor-host .CodeMirror-scroll {
  min-height: 0;
  height: 100%;
}

body.theme-premium #kb-window-editor-host {
  border-color: #d4a0a8;
  background: #fffbfc;
}

body.theme-premium #kb-window-editor-host.dragover {
  border-color: #c49a9e;
  background: #fff2f5;
  box-shadow: 0 0 0 3px rgba(196, 154, 158, 0.18);
}

body.theme-premium .kb-window-preview-pane {
  border-color: #e0c0c4;
  background: #fffbfc;
}

body.theme-premium .kb-window-preview {
  border-top-color: #e0c0c4;
}

@media (max-width: 1100px) {
  .kb-window-split {
    grid-template-columns: 1fr;
  }

  .kb-window-preview {
    max-height: none;
  }
}
