:root {
  --light-cyan: #bdeff2;
  --teal: #2f9fb3;
  --dark-navy: #102a43;
  --light-blue: #d9f0ff;
  --medium-blue: #4fa3d1;
  --surface: #f5fbfe;
  --text: #17324d;
  --muted: #60758a;
}

body {
  background: var(--surface);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--light-blue), #fff 58%, var(--light-cyan));
}

.login-panel {
  width: min(430px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid var(--light-cyan);
  border-radius: 12px;
  box-shadow: 0 22px 60px rgba(16, 42, 67, .14);
  padding: 34px;
}

.login-brand {
  color: var(--dark-navy);
  font-weight: 800;
  font-size: 1.65rem;
}

.login-logo,
.dashboard-logo {
  max-width: 260px;
  height: auto;
  object-fit: contain;
  margin-bottom: 12px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 288px;
  background: var(--dark-navy);
  color: #fff;
  transition: width .2s ease;
  overflow-x: hidden;
  flex: 0 0 auto;
  box-shadow: 8px 0 28px rgba(16, 42, 67, .12);
}

.sidebar.collapsed {
  width: 78px;
}

.sidebar-head {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid rgba(189, 239, 242, .16);
}

.user-toggle {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 1.25rem;
  flex: 0 0 auto;
}

.sidebar-brand {
  display: grid;
  line-height: 1.1;
}

.sidebar-logo {
  max-width: 185px;
  max-height: 42px;
  object-fit: contain;
  transition: opacity .2s ease;
}

.sidebar.collapsed .sidebar-logo {
  display: none;
}

.sidebar-brand small {
  color: var(--light-cyan);
}

.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .parent-link strong,
.sidebar.collapsed .child-link span,
.sidebar.collapsed .parent-chevron {
  display: none;
}

.sidebar-nav {
  padding: 12px 10px 24px;
}

.nav-section {
  margin-bottom: 6px;
}

.parent-link,
.child-link {
  width: 100%;
  border: 0;
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
}

.parent-link {
  background: transparent;
  padding: 11px 12px;
  font-weight: 800;
}

.parent-link .nav-icon,
.child-link > i {
  width: 22px;
  min-width: 22px;
  text-align: center;
  font-size: 1.05rem;
}

.parent-link:hover,
.child-link:hover,
.child-link.active {
  background: rgba(47, 159, 179, .9);
  color: #fff;
}

.parent-chevron {
  margin-left: auto;
  transition: transform .2s ease;
}

.parent-link:not(.collapsed) .parent-chevron {
  transform: rotate(180deg);
}

.child-link {
  padding: 9px 12px 9px 42px;
  color: rgba(255,255,255,.88);
  font-size: .94rem;
}

.sidebar.collapsed .child-link {
  padding-left: 14px;
  justify-content: center;
}

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

.menu-icon-preview {
  min-width: 46px;
  justify-content: center;
}

.main-area {
  flex: 1;
  min-width: 0;
}

.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--light-cyan);
}

.brand {
  font-weight: 800;
  color: var(--dark-navy);
}

.topbar small,
.page-head p {
  color: var(--muted);
}

.dashboard-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  background: #fff;
  border: 1px solid var(--light-cyan);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: 0 12px 28px rgba(16,42,67,.06);
}

.dashboard-hero h1 {
  margin: 0;
  font-size: 1.75rem;
}

.dashboard-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.dash-kpi {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--light-cyan);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 10px 24px rgba(16,42,67,.055);
}

.dash-kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--light-blue);
  color: var(--teal);
  font-size: 1.35rem;
}

.dash-kpi-label {
  color: var(--muted);
  font-size: .86rem;
}

.dash-kpi-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--dark-navy);
}

.kpi-danger .dash-kpi-icon { background: #ffe4e6; color: #be123c; }
.kpi-warning .dash-kpi-icon { background: #fff7d6; color: #a16207; }
.kpi-success .dash-kpi-icon { background: #dcfce7; color: #15803d; }
.kpi-info .dash-kpi-icon { background: #e0f2fe; color: #0369a1; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, .7fr);
  gap: 16px;
  margin-bottom: 18px;
}

.dashboard-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-grid.recent {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dash-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.quick-action {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--light-cyan);
  border-radius: 8px;
  text-decoration: none;
  color: var(--dark-navy);
  background: #f8fdff;
  font-weight: 700;
}

.quick-action:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.alert-stack {
  display: grid;
  gap: 10px;
}

.dash-alert {
  display: grid;
  gap: 3px;
  border-radius: 8px;
  padding: 10px 12px;
  background: #f8fdff;
  border-left: 4px solid var(--teal);
}

.dash-alert.alert-danger { border-left-color: #be123c; background: #fff1f2; }
.dash-alert.alert-warning { border-left-color: #a16207; background: #fffbeb; }
.dash-alert.alert-success { border-left-color: #15803d; background: #f0fdf4; }

.progress-row,
.metric-line {
  display: grid;
  grid-template-columns: 90px 1fr 80px;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.metric-line {
  grid-template-columns: 1fr auto;
}

.progress {
  height: 8px;
  background: #e8f6fb;
}

.progress-bar {
  background: var(--teal);
}

@media (max-width: 1100px) {
  .dashboard-grid,
  .dashboard-grid.three,
  .dashboard-grid.recent {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .dashboard-hero {
    align-items: flex-start;
    flex-direction: column;
  }
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-brand img {
  width: 118px;
  max-height: 36px;
  object-fit: contain;
}

.user-pill {
  background: var(--light-blue);
  border-radius: 999px;
  padding: 7px 13px;
  color: var(--dark-navy);
}

.content {
  padding: 28px;
}

.breadcrumb-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  margin-bottom: 10px;
  font-size: .92rem;
}

.breadcrumb-row a {
  color: var(--teal);
  text-decoration: none;
  font-weight: 700;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  color: var(--dark-navy);
  font-size: 1.75rem;
  font-weight: 800;
}

.erp-card,
.panel {
  background: #fff;
  border: 1px solid rgba(189, 239, 242, .9);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 12px 34px rgba(16, 42, 67, .07);
}

.erp-card h5 {
  color: var(--dark-navy);
  font-weight: 800;
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(260px, 420px) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

.table-shell {
  border: 1px solid var(--light-cyan);
  border-radius: 10px;
  overflow: hidden;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  background: var(--light-blue);
  color: var(--dark-navy);
  font-weight: 800;
  white-space: nowrap;
}

.table tbody td {
  white-space: nowrap;
  vertical-align: middle;
}

.action-col {
  width: 110px;
}

.modal-sm { --bs-modal-width: min(600px, calc(100vw - 32px)); }
.modal-lg { --bs-modal-width: min(900px, calc(100vw - 32px)); }
.modal-xl { --bs-modal-width: min(1100px, calc(100vw - 40px)); }
.modal-xxl { --bs-modal-width: min(1240px, calc(100vw - 40px)); }

.modal-dialog {
  margin-left: auto;
  margin-right: auto;
}

.modal-dialog-centered {
  min-height: calc(100% - 2rem);
}

.modal-dialog-scrollable .modal-content {
  max-height: min(860px, calc(100vh - 48px));
}

.modal-content {
  border: 0;
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(16, 42, 67, .2);
}

.crud-modal {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.crud-modal form {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
}

.crud-modal-header {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--light-cyan);
  background: var(--surface);
  padding: 18px 22px;
}

.crud-modal-header .btn-close {
  align-self: flex-start;
  margin-top: 2px;
}

.modal-title {
  color: var(--dark-navy);
  font-weight: 800;
}

.crud-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  background: #fff;
  padding: 22px 22px 28px;
  overflow-y: auto;
}

.crud-modal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 248px;
  gap: 24px;
  align-items: start;
}

.crud-modal-grid.without-image {
  grid-template-columns: 1fr;
}

.crud-fields-panel {
  min-width: 0;
}

.form-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px 18px;
  align-items: start;
}

.field-cell {
  min-width: 0;
}

.field-cell.span-2,
.span-2 {
  grid-column: 1 / -1;
}

.crud-fields-panel .form-label {
  color: var(--dark-navy);
  font-weight: 700;
  margin-bottom: 6px;
}

.required-star {
  color: #dc3545;
  font-weight: 900;
}

.crud-fields-panel .form-control,
.crud-fields-panel .form-select,
.select2-container--bootstrap-5 .select2-selection {
  min-height: 42px;
  border-radius: 8px;
  border-color: #c8e7f1;
}

.form-switch-card {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 12px 10px 44px;
  background: #f7fcff;
  border: 1px solid #d5edf5;
  border-radius: 10px;
  margin-top: 24px;
}

.crud-image-panel {
  position: sticky;
  top: 0;
  align-self: start;
  padding: 14px 13px;
  background: #f7fcff;
  border: 1px solid #d5edf5;
  border-radius: 12px;
}

.image-uploader-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.image-clear {
  color: var(--teal);
  text-decoration: none;
  padding: 0;
}

.image-dropzone {
  width: 220px;
  height: 160px;
  max-width: 100%;
  position: relative;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 2px dashed #87d4df;
  border-radius: 12px;
  background: rgba(217, 240, 255, .48);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.image-dropzone:hover,
.image-dropzone.drag-over {
  border-color: var(--teal);
  background: rgba(189, 239, 242, .62);
  box-shadow: 0 10px 24px rgba(47, 159, 179, .14);
}

.image-dropzone:disabled {
  cursor: not-allowed;
  opacity: .82;
}

.image-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: 0;
  border-radius: 8px;
  background: #fff;
}

.image-placeholder {
  display: grid;
  gap: 4px;
  justify-items: center;
  pointer-events: none;
}

.image-placeholder i {
  font-size: 2rem;
  color: var(--teal);
}

.image-placeholder strong {
  color: var(--dark-navy);
  font-size: .92rem;
}

.image-placeholder small {
  color: var(--muted);
}

.preview-status {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 8px;
  place-content: center;
  background: rgba(255, 255, 255, .86);
  color: var(--dark-navy);
  font-size: .9rem;
  z-index: 2;
}

.preview-status {
  align-items: center;
}

.preview-error {
  color: #b42318;
  font-size: .85rem;
  margin-top: 8px;
}

.crud-modal-footer {
  z-index: 4;
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  background: #fff;
  border-top: 1px solid var(--light-cyan);
  box-shadow: 0 -10px 22px rgba(16, 42, 67, .05);
}

.crud-modal-footer .btn {
  min-width: 104px;
  font-weight: 700;
}

.list-thumb {
  width: 56px;
  height: 36px;
  object-fit: contain;
  border: 1px solid var(--light-cyan);
  border-radius: 6px;
  background: #fff;
  padding: 3px;
}

.btn-primary {
  --bs-btn-bg: var(--teal);
  --bs-btn-border-color: var(--teal);
  --bs-btn-hover-bg: var(--medium-blue);
  --bs-btn-hover-border-color: var(--medium-blue);
}

.btn-outline-primary {
  --bs-btn-color: var(--teal);
  --bs-btn-border-color: var(--teal);
  --bs-btn-hover-bg: var(--teal);
  --bs-btn-hover-border-color: var(--teal);
}

.coa-panel {
  min-height: 520px;
}

.coa-tree {
  min-height: 430px;
  border: 1px solid var(--light-cyan);
  border-radius: 12px;
  background: #fbfeff;
  padding: 12px;
  overflow: auto;
}

.coa-node-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.coa-node-row {
  display: grid;
  grid-template-columns: 28px 24px minmax(86px, 110px) minmax(220px, 1fr) auto auto auto 38px;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  margin: 3px 0;
  padding: 6px 8px 6px calc(8px + (var(--level) * 24px));
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--dark-navy);
}

.coa-node-row:hover {
  background: var(--light-blue);
  border-color: var(--light-cyan);
}

.coa-node.inactive > .coa-node-row {
  opacity: .58;
  filter: grayscale(.15);
}

.coa-node.collapsed > .coa-children {
  display: none;
}

.coa-node.collapsed > .coa-node-row .coa-expander i {
  transform: rotate(-90deg);
}

.coa-expander {
  border: 0;
  background: transparent;
  color: var(--teal);
}

.coa-node-icon {
  color: var(--teal);
  font-size: 1.12rem;
}

.coa-code {
  font-weight: 800;
  color: var(--dark-navy);
}

.coa-name {
  font-weight: 700;
}

.coa-badge {
  border: 1px solid #c8e7f1;
  background: #fff;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: .78rem;
  white-space: nowrap;
}

.coa-badge.postable {
  color: #0f766e;
  border-color: #99f6e4;
  background: #ecfeff;
}

.coa-badge.group {
  color: #1d4ed8;
  border-color: #bfdbfe;
  background: #eff6ff;
}

.coa-badge.active {
  color: #166534;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.coa-badge.inactive {
  color: #64748b;
  border-color: #cbd5e1;
  background: #f8fafc;
}

.coa-context-menu {
  position: absolute;
  z-index: 2000;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--light-cyan);
  border-radius: 10px;
  box-shadow: 0 18px 46px rgba(16, 42, 67, .18);
  padding: 6px;
}

.coa-context-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--dark-navy);
  text-align: left;
}

.coa-context-menu button:hover {
  background: var(--light-blue);
}

.coa-empty {
  min-height: 340px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #9bdce5;
  border-radius: 12px;
}

.form-control:focus,
.form-select:focus,
.select2-container--bootstrap-5 .select2-selection:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 .2rem rgba(47, 159, 179, .16);
}

.form-with-media {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
  gap: 22px;
  align-items: start;
}

.form-main-fields {
  min-width: 0;
}

.form-media-panel {
  display: grid;
  gap: 14px;
  position: sticky;
  top: 90px;
}

.upload-card {
  border: 1px solid #cdeaf0;
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  box-shadow: 0 10px 28px rgba(16, 42, 67, .06);
}

.upload-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.upload-remove {
  border: 0;
  background: transparent;
  color: #b91c1c;
  font-size: .82rem;
  font-weight: 700;
  padding: 0;
}

.upload-dropzone,
.file-dropzone {
  width: 100%;
  min-height: 148px;
  border: 1.5px dashed #8bcbd7;
  border-radius: 10px;
  background: #f8fdff;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  color: #35586a;
  transition: border-color .15s ease, background .15s ease;
}

.upload-dropzone.drag-over,
.file-dropzone.drag-over {
  border-color: var(--teal);
  background: #ecfeff;
}

.upload-preview {
  max-width: 100%;
  max-height: 210px;
  border-radius: 8px;
  object-fit: contain;
}

.upload-placeholder {
  display: grid;
  gap: 8px;
  justify-items: center;
  font-weight: 700;
}

.upload-placeholder i {
  font-size: 2rem;
  color: var(--teal);
}

.upload-help,
.file-name-preview {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: .82rem;
}

.file-name-preview {
  font-weight: 700;
  color: var(--dark-navy);
  word-break: break-word;
}

.preview-error {
  margin-top: 8px;
  color: #b91c1c;
  font-size: .82rem;
}

.preview-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: .82rem;
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  body {
    background: #fff !important;
    color: #111827 !important;
  }

  .sidebar,
  .topbar,
  .page-head .btn,
  .btn,
  .quick-actions,
  .dataTables_wrapper .dt-buttons,
  .dataTables_filter,
  .dataTables_length,
  .dataTables_info,
  .dataTables_paginate {
    display: none !important;
  }

  .app-shell,
  .main-area,
  .content {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }

  .panel,
  .dash-section {
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 11px !important;
  }

  th,
  td {
    border: 1px solid #d1d5db !important;
    padding: 6px !important;
  }
}

div.dt-container .dt-search input,
div.dt-container .dt-length select {
  border-radius: 8px;
  border-color: var(--light-cyan);
}

@media (max-width: 900px) {
  .sidebar {
    width: 78px;
  }
  .sidebar .sidebar-brand,
  .sidebar .parent-link strong,
  .sidebar .child-link span,
  .sidebar .parent-chevron {
    display: none;
  }
  .content {
    padding: 18px;
  }
  .page-head {
    flex-direction: column;
  }
  .toolbar-row {
    grid-template-columns: 1fr;
  }
  .crud-modal-grid {
    grid-template-columns: 1fr;
  }
  .form-field-grid {
    grid-template-columns: 1fr;
  }
  .field-cell.span-2 {
    grid-column: auto;
  }
  .crud-image-panel {
    position: static;
    order: -1;
  }
  .image-dropzone {
    width: 100%;
  }
  .form-with-media {
    grid-template-columns: 1fr;
  }
  .form-media-panel {
    position: static;
  }
  .modal-dialog {
    width: auto;
    max-width: none;
    margin: 10px;
  }
  .modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - 20px);
  }
}
