:root {
  color-scheme: light;
  --primary: #087a63;
  --primary-dark: #075d4e;
  --text-muted: #526171;
  --sidebar-width: 252px;
  --sidebar-bg: #142235;
  --sidebar-bg-hover: #20334a;
  --sidebar-border: rgba(255, 255, 255, 0.09);

  --bs-primary: #087a63;
  --bs-primary-rgb: 8, 122, 99;
  --bs-link-color: #086c58;
  --bs-link-hover-color: #075645;
  --bs-body-color: #1b2735;
  --bs-body-bg: #f5f7f9;
  --bs-secondary-color: #526171;
  --bs-border-color: #dce3e9;
  --bs-border-radius: 0.625rem;
  --bs-border-radius-lg: 0.875rem;
  --bs-focus-ring-color: rgba(8, 122, 99, 0.28);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; }

a { text-underline-offset: 0.16em; }

:focus-visible {
  outline: 3px solid #0a8a70;
  outline-offset: 3px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.sidebar-link:focus-visible,
.sidebar-signout:focus-visible {
  outline: 3px solid #19bd98;
  outline-offset: 2px;
  box-shadow: none;
}

.btn-primary {
  --bs-btn-color: #fff;
  --bs-btn-bg: #087a63;
  --bs-btn-border-color: #087a63;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #075d4e;
  --bs-btn-hover-border-color: #075d4e;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #064d41;
  --bs-btn-active-border-color: #064d41;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: #527e73;
  --bs-btn-disabled-border-color: #527e73;
  font-weight: 650;
}

.btn-outline-primary {
  --bs-btn-color: #086c58;
  --bs-btn-border-color: #087a63;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #087a63;
  --bs-btn-hover-border-color: #087a63;
}

.login-view {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 5vw, 48px);
  background:
    radial-gradient(ellipse at 12% 4%, rgba(8, 122, 99, 0.09), transparent 34rem),
    #f3f6f7;
}

.login-card {
  width: min(100%, 420px);
  overflow: hidden;
  border: 1px solid #e0e7eb;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 22px 60px rgba(25, 47, 58, 0.11);
  text-align: left;
}

.login-card .card-body { padding: clamp(28px, 7vw, 40px) !important; }

.login-logo {
  color: #126e5b;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 1;
}

.login-subtitle {
  margin: 10px 0 28px;
  color: #526171;
  font-size: 14px;
}

#login-form { gap: 12px !important; }

#login-form .form-control {
  min-height: 46px;
  border-color: #d6dfe5;
  border-radius: 9px;
  background: #fbfcfd;
}

#login-form .form-control:focus {
  border-color: #087a63;
  box-shadow: 0 0 0 0.2rem rgba(8, 122, 99, 0.16);
}

#login-submit { min-height: 46px; margin-top: 8px !important; }

.login-error {
  margin: 16px 0 0;
  color: #a32828;
  font-size: 13px;
  font-weight: 600;
}

.login-skip { margin-top: 14px; font-size: 12.5px; }

.security-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding: 12px 16px;
  border: 1px solid #e7c46d;
  border-radius: var(--bs-border-radius);
  background: #fff8e6;
  color: #573d08;
  font-size: 13px;
}

.config-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--bs-border-color);
}

.config-row:last-child { border-bottom: 0; }
.config-row label { flex: 0 0 180px; font-size: 13.5px; font-weight: 650; }
.config-row input { min-width: 0; flex: 1; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.app-shell {
  display: flex;
  min-height: 100vh;
  background: var(--bs-body-bg);
}

.sidebar {
  position: sticky;
  z-index: 1040;
  top: 0;
  display: flex;
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  flex: 0 0 var(--sidebar-width);
  flex-direction: column;
  align-self: flex-start;
  padding: 17px 12px 12px;
  border-right: 1px solid var(--sidebar-border);
  background: var(--sidebar-bg);
  color: #f4f7fb;
}

.sidebar-brand {
  display: flex;
  min-height: 52px;
  align-items: center;
  gap: 9px;
  margin: 0 4px 14px;
  padding: 0 8px 13px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  place-items: center;
  border-radius: 9px;
  background: #b8eddf;
  color: #124c40;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.06em;
}

.brand-name {
  color: #fff;
  font-size: 18px;
  font-weight: 760;
  letter-spacing: -0.04em;
}

.brand-label {
  margin-left: auto;
  padding: 3px 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: #d0dbe7;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #526276 transparent;
  scrollbar-width: thin;
}

.sidebar-heading {
  padding: 13px 10px 5px;
  color: #bdc9d7;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.105em;
  line-height: 1.3;
  text-transform: uppercase;
}

.sidebar-heading:first-child { padding-top: 2px; }

.sidebar-link {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: #d5deea;
  font-size: 12.5px;
  font-weight: 520;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.sidebar-link > i {
  width: 17px;
  flex: 0 0 17px;
  color: #c2cfdd;
  font-size: 15px;
  text-align: center;
}

.sidebar-link:hover {
  border-color: rgba(255, 255, 255, 0.07);
  background: var(--sidebar-bg-hover);
  color: #fff;
}

.sidebar-link:hover > i { color: #fff; }

.sidebar-link.active {
  border-color: rgba(157, 228, 209, 0.15);
  background: #23483f;
  color: #d7f8ee;
  font-weight: 680;
}

.sidebar-link.active > i { color: #b7f0df; }

.nav-badge {
  min-width: 21px;
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 999px;
  background: #b8eddf;
  color: #153f35;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.nav-badge-warning { background: #ffe09a; color: #513600; }

.sidebar-signout {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 10px;
  border-top: 1px solid var(--sidebar-border);
  border-radius: 0;
  color: #d0dbe7;
  font-size: 12.5px;
  text-align: left;
  text-decoration: none;
}

.sidebar-signout i { font-size: 15px; }
.sidebar-signout:hover { color: #fff; }

.sidebar-toggle {
  position: fixed;
  z-index: 1050;
  top: 12px;
  left: 12px;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border: 1px solid #dbe3e9;
  border-radius: 10px;
  background: #fff;
  color: #173142;
  box-shadow: 0 3px 12px rgba(23, 49, 66, 0.12);
}

.sidebar-toggle:hover { background: #f2f6f7; color: #112a37; }
.sidebar-toggle i { font-size: 21px; line-height: 1; }

.sidebar-backdrop {
  position: fixed;
  z-index: 1030;
  inset: 0;
  background: rgba(11, 22, 34, 0.58);
  backdrop-filter: blur(2px);
}

.content {
  width: 100%;
  min-width: 0;
  flex: 1;
  padding: clamp(22px, 3vw, 40px);
}

.content > .section {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
}

.section h1 {
  margin: 0 0 22px;
  color: #172535;
  font-size: clamp(23px, 2.4vw, 29px);
  font-weight: 730;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

.section h2 { color: #1b2c3b; letter-spacing: -0.02em; }
.section h3 { color: #263949; }
.content p { overflow-wrap: anywhere; }

.content input[type="text"],
.content input[type="number"],
.content input[type="email"],
.content input[type="tel"],
.content input[type="date"],
.content input[type="datetime-local"],
.content select,
.content textarea {
  display: inline-block;
  max-width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid #cbd5dc;
  border-radius: 0.5rem;
  background-color: #fff;
  color: #1b2735;
  font-size: 0.9rem;
  line-height: 1.45;
}

.content input[type="text"]:focus,
.content input[type="number"]:focus,
.content input[type="email"]:focus,
.content input[type="tel"]:focus,
.content input[type="date"]:focus,
.content input[type="datetime-local"]:focus,
.content select:focus,
.content textarea:focus {
  border-color: #087a63;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(8, 122, 99, 0.17);
}

.content input::placeholder,
.content textarea::placeholder { color: #647381; opacity: 1; }

.content :disabled,
.content [aria-disabled="true"] { cursor: not-allowed; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 18px;
  border: 1px solid #dfe6eb;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(24, 45, 59, 0.035);
}

.stat-card .value { color: #172d3a; font-size: 26px; font-weight: 780; letter-spacing: -0.035em; }
.stat-card .label { margin-top: 4px; color: #526171; font-size: 12.5px; }

.card {
  overflow: hidden;
  border-color: #dfe6eb;
  border-radius: 12px;
  background-color: #fff;
  box-shadow: 0 2px 9px rgba(24, 45, 59, 0.035);
}

.card-header { border-bottom-color: #e5ebef; background: #fff; font-weight: 650; }
.card-footer { border-top-color: #e5ebef; background: #fbfcfd; }

.table { --bs-table-color: #233342; --bs-table-border-color: #e1e7ec; }
.table > thead { color: #435363; }
.table > thead th { font-size: 12px; font-weight: 700; }
.table > :not(caption) > * > * { padding: 0.7rem 0.75rem; }
th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable-th:hover { color: var(--bs-primary); }
.table-responsive { border-radius: 10px; }

.doc-link { font-size: 12.5px; }

.event-editor { margin-bottom: 22px; }

.event-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--bs-border-color);
}

.event-editor-header h2 { margin: 0; font-size: 17px; font-weight: 750; }
.event-editor-header p { margin: 5px 0 0; color: #526171; font-size: 13px; }
.event-editor-body { padding: 18px 22px 22px; }

.event-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  align-items: end;
  gap: 14px;
}

.event-form-section { grid-column: 1 / -1; padding-top: 14px; border-top: 1px solid var(--bs-border-color); }
.event-form-section:first-child { padding-top: 0; border-top: 0; }
.event-form-section-title { margin: 0 0 12px; font-size: 13px; font-weight: 750; }
.event-form-field { min-width: 0; }
.event-form-field > label { display: block; margin-bottom: 5px; color: #526171; font-size: 12px; font-weight: 650; }
.event-form-field input:not([type="checkbox"]), .event-form-field select, .event-form-field textarea { width: 100% !important; }
.event-form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; }
.event-meeting-point-form { padding: 14px; border-radius: 10px; background: #f2f6f7; }
.event-table-card { margin-top: 12px; }

.support-message-list {
  max-height: 55vh;
  min-height: 180px;
  margin-bottom: 16px;
  padding: 16px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.support-message { margin-bottom: 14px; }
.support-message:last-child { margin-bottom: 0; }
.support-message-outgoing { text-align: right; }
.support-message-meta { margin-bottom: 3px; color: #526171; font-size: 11px; }

.support-message-bubble {
  display: inline-block;
  max-width: min(78%, 680px);
  padding: 9px 13px;
  border-radius: 12px 12px 12px 4px;
  background: #edf2f5;
  color: #1b2735;
  overflow-wrap: anywhere;
  text-align: left;
  white-space: pre-wrap;
}

.support-message-bubble-outgoing {
  border-radius: 12px 12px 4px 12px;
  background: #d5f2e9;
  color: #18382f;
}

.support-message-receipt { margin-top: 3px; color: #526171; font-size: 11px; }

.agent-phone {
  width: min(240px, 100%);
  overflow: hidden;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.agent-phone-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--bs-border-color);
}

.agent-phone-screen { min-height: 120px; padding: 14px; background: var(--sidebar-bg); color: #fff; font-size: 12.5px; }

.empty-state { padding: 40px 20px; color: #526171; text-align: center; }
.loading { padding: 20px; color: #526171; }

.toast {
  position: fixed;
  z-index: 1100;
  bottom: 24px;
  left: 50%;
  max-width: min(90vw, 560px);
  padding: 12px 20px;
  transform: translateX(-50%);
  border: 1px solid #d5dfe5;
  border-radius: 10px;
  background: #fff;
  color: #1b2735;
  box-shadow: 0 10px 28px rgba(17, 36, 48, 0.16);
  font-size: 13.5px;
}

.crop-overlay {
  position: fixed;
  z-index: 2000;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
}

.crop-panel {
  display: flex;
  width: min(920px, 100%);
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: #fff;
}

.crop-title { font-weight: 700; }
.crop-stage { height: 62vh; overflow: hidden; border-radius: 8px; background: #111; }
.crop-stage img { display: block; max-width: 100%; }
.crop-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    visibility: hidden;
    transform: translateX(-100%);
    box-shadow: 8px 0 28px rgba(8, 20, 32, 0.22);
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }

  .sidebar.open {
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
  }

  .content { padding: 68px 22px 24px; }
}

@media (max-width: 575.98px) {
  .content { padding: 66px 14px 20px; }
  .section h1 { margin-bottom: 17px; }
  .event-editor-header, .event-editor-body { padding-right: 16px; padding-left: 16px; }
  .event-form-grid { grid-template-columns: minmax(0, 1fr); }
  .event-form-actions { flex-wrap: wrap; }
  .support-message-bubble { max-width: 92%; }
  .config-row { align-items: stretch; flex-direction: column; }
  .config-row label { flex: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
