* {
  box-sizing: border-box;
}

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f9fbff;
  --border: #dbe5f1;
  --border-soft: #e8eef5;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --hover: #f5f9ff;
  --danger-soft: #fff1f2;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Prompt', sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

a {
  text-decoration: none;
  color: inherit;
}

img {
  max-width: 100%;
  display: block;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}

/* SIDEBAR */
.app-sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  min-width: 0;
}

.brand-logo {
  width: 36px;
  height: 54px;
  min-width: 36px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
  overflow: hidden;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  color: #0b1b44;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  color: #334155;
  text-decoration: none;
  transition: .18s ease;
}

.sidebar-link i {
  font-size: 16px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background: #f8fbff;
  color: #1d4ed8;
}

.sidebar-link.active {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px #bfdbfe;
}

.sidebar-link-danger {
  color: #b91c1c;
}

.sidebar-link-danger:hover {
  background: #fff1f2;
  color: #b91c1c;
}

/* MAIN */
.app-main {
  flex: 1;
  margin-left: 250px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* TOPBAR */
.topbar {
  height: 72px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  position: sticky;
  top: 0;
  z-index: 1030;
  backdrop-filter: blur(8px);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  color: #0b1b44;
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.topbar-clock {
  background: var(--surface-2);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 14px;
  font-weight: 600;
  min-width: 96px;
  text-align: center;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 10px;
  font-weight: 500;
  color: #334155;
}

/* CONTENT */
.app-content {
  padding: 24px;
  flex: 1;
  min-width: 0;
}

.page-header {
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: #0b1b44;
}

.page-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
}

.content-card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.content-card-body {
  padding: 24px;
}

.content-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: #0b1b44;
}

.content-text {
  margin: 0;
  color: #475569;
  line-height: 1.7;
}

/* FOOTER */
.app-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-open {
  overflow: hidden;
}

/* MOBILE */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
  }

  .app-sidebar.show {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

.topbar {
  height: 72px;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid var(--border);

  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;

  position: fixed;
  top: 0;
  left: 250px;
  right: 0;

  z-index: 1030;
  backdrop-filter: blur(8px);
}

html.preload-ui,
html.preload-ui body,
html.preload-ui .app-shell,
html.preload-ui .app-sidebar,
html.preload-ui .app-main,
html.preload-ui .topbar,
html.preload-ui .app-footer {
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

html:not(.preload-ui),
html:not(.preload-ui) body,
html:not(.preload-ui) .app-shell,
html:not(.preload-ui) .app-sidebar,
html:not(.preload-ui) .app-main,
html:not(.preload-ui) .topbar,
html:not(.preload-ui) .app-footer,
body.ui-ready,
body.ui-ready .app-shell,
body.ui-ready .app-sidebar,
body.ui-ready .app-main,
body.ui-ready .topbar,
body.ui-html:not(.preload-ui) .app-footer {
  opacity: 1;
}

}

/* ===== UTILITY CLASSES ===== */
.d-none {
  display: none !important;
}

.d-block {
  display: block !important;
}

.d-flex {
  display: flex !important;
}

.mb-3 {
  margin-bottom: 1rem;
}

/* ===== FORM CONTROLS ===== */
.form-control {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text);
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  font-family: inherit;
}

.form-control:focus {
  color: var(--text);
  background-color: #fff;
  border-color: var(--primary);
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(29, 78, 216, 0.25);
}

.form-control:disabled,
.form-control[readonly] {
  background-color: #e9ecef;
  opacity: 1;
}

/* ===== SECTION TITLE ===== */
.section-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

.section-subtitle {
  margin: 0.375rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* =========================
   SIDEBAR ENHANCED
========================= */
:root {
  --sidebar-width: 250px;
  --sidebar-collapsed-width: 84px;
}

.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  transition: width .22s ease, min-width .22s ease, transform .25s ease;
}

.app-main {
  margin-left: var(--sidebar-width);
  transition: margin-left .22s ease;
}

.topbar {
  transition: left .22s ease, right .22s ease;
}

.sidebar-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 4px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar-collapse-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  background: #fff;
  color: #334155;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: .18s ease;
}

.sidebar-collapse-btn:hover {
  background: var(--hover);
  color: var(--primary);
  border-color: var(--primary-border);
}

.sidebar-divider {
  height: 1px;
  background: var(--border-soft);
  margin: 12px 10px;
}

.sidebar-section {
  margin-top: 8px;
}

.sidebar-section-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #475569;
  cursor: pointer;
  transition: .18s ease;
}

.sidebar-section-toggle:hover {
  background: #f8fbff;
  color: var(--primary);
}

.sidebar-section-toggle-left,
.sidebar-section-toggle-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-section-title {
  font-size: 13px;
  font-weight: 800;
  color: #64748b;
  letter-spacing: .2px;
}

.sidebar-section-toggle i.bi:not(.accordion-arrow) {
  font-size: 16px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.accordion-arrow {
  font-size: 14px;
  transition: transform .2s ease;
}

.accordion-item.is-open .accordion-arrow {
  transform: rotate(0deg);
}

.accordion-item:not(.is-open) .accordion-arrow {
  transform: rotate(-90deg);
}

.sidebar-section-body {
  overflow: hidden;
  max-height: 500px;
  transition: max-height .22s ease, opacity .18s ease, margin-top .18s ease;
  opacity: 1;
  margin-top: 2px;
}

.accordion-item:not(.is-open) .sidebar-section-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

.sidebar-sublink {
  margin-left: 6px;
  padding-left: 18px;
  position: relative;
}

.sidebar-sublink::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #cbd5e1;
  transform: translateY(-50%);
}

.sidebar-sublink.active::before,
.sidebar-sublink:hover::before {
  background: var(--primary);
}

.sidebar-badge {
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #1d4ed8;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}

.badge-soft {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.badge-chat {
  background: #0f766e;
  color: #fff;
}

.badge-chat-soft {
  background: #ecfeff;
  color: #0f766e;
  border: 1px solid #a5f3fc;
}

body.sidebar-collapsed .app-sidebar {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .app-main {
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .sidebar-text,
body.sidebar-collapsed .sidebar-section-title,
body.sidebar-collapsed .accordion-arrow,
body.sidebar-collapsed .sidebar-section-toggle-right .sidebar-badge,
body.sidebar-collapsed .sidebar-link .sidebar-badge,
body.sidebar-collapsed .sidebar-divider {
  display: none !important;
}

body.sidebar-collapsed .sidebar-brand {
  padding-bottom: 12px;
}

body.sidebar-collapsed .brand-link {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-toolbar {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-link,
body.sidebar-collapsed .sidebar-section-toggle {
  justify-content: center;
  padding-left: 10px;
  padding-right: 10px;
}

body.sidebar-collapsed .sidebar-sublink {
  margin-left: 0;
  padding-left: 10px;
}

body.sidebar-collapsed .sidebar-sublink::before {
  display: none;
}

body.sidebar-collapsed .sidebar-link i,
body.sidebar-collapsed .sidebar-section-toggle i.bi:not(.accordion-arrow) {
  width: auto;
  font-size: 18px;
}

body.sidebar-collapsed .sidebar-section-body {
  max-height: 500px;
  opacity: 1;
  margin-top: 2px;
}

@media (max-width: 991.98px) {
  .app-main {
    margin-left: 0;
  }

  body.sidebar-collapsed .app-main {
    margin-left: 0;
  }
}