:root {
  --bg: #eef2f4;
  --bg-2: #f8f9fa;
  --panel: #ffffff;
  --panel-2: #f5f7f8;
  --border: #e6e9ec;
  --text: #333333;
  --text-dim: #525c69;
  --accent: #2fc6f6;
  --accent-dark: #14a6d4;
  --accent-2: #9dcf00;
  --accent-3: #ff5752;
  --accent-4: #ffa900;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --font: "Open Sans", "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  height: 100%;
  max-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body::before {
  display: none;
}

.app {
  display: flex;
  height: 100%;
  max-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #2b2f33;
  display: block;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-name {
  font-family: var(--font);
  font-weight: 700;
  font-size: 15px;
}
.brand-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.tab:hover {
  background: var(--panel);
  color: var(--text);
}

.tab.active {
  background: #e5f9fe;
  color: #008dba;
  box-shadow: none;
}

.tab-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  padding: 16px 4px 0;
  margin-top: auto;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}

.reglam-credit {
  display: block;
  line-height: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 180, 255, 0.18);
  transition: box-shadow 0.2s, transform 0.2s;
}

.reglam-credit:hover {
  box-shadow: 0 0 0 1px #00d4ff, 0 4px 14px rgba(0, 180, 255, 0.28);
  transform: translateY(-1px);
}

.reglam-credit img {
  width: 100%;
  height: auto;
  display: block;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: none;
}

/* ---------- Main ---------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 28px 32px 48px;
  overflow-x: hidden;
  overflow-y: auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar-title h1 {
  font-family: var(--font);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0;
}

.topbar-title p {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 6px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-export {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  font-weight: 600;
}
.btn-export:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.btn-apply {
  background: var(--accent);
  color: #fff;
  box-shadow: none;
  font-weight: 600;
}
.btn-apply:hover {
  background: var(--accent-dark);
}

/* ---------- Filters ---------- */
.filters {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-group select,
.filter-group input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 14px;
  min-width: 180px;
}

.filter-group select[multiple] {
  min-height: 44px;
  max-height: 120px;
}

.filter-group input[type="date"] {
  color-scheme: light;
}

.range {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.range label {
  text-transform: none;
}

.hidden {
  display: none !important;
}

/* ---------- Content ---------- */
.content {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

#dashboard,
.section {
  min-width: 0;
  max-width: 100%;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  gap: 16px;
  color: var(--text-dim);
}

.loading.overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  margin: 0;
  background: rgba(238, 242, 244, 0.78);
  padding: 80px 0;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error {
  background: rgba(255, 91, 85, 0.1);
  border: 1px solid rgba(255, 91, 85, 0.4);
  color: #ff8a85;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

/* ---------- Dashboard ---------- */
.section {
  margin-bottom: 36px;
}

.section-title {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title::before {
  content: "";
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background: var(--accent);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s;
  cursor: help;
}

.kpi-card:hover {
  box-shadow: 0 2px 8px rgba(47, 198, 246, 0.18);
}

.kpi-card.kpi-click {
  cursor: pointer;
}

.kpi-card.kpi-click:hover {
  border-color: var(--accent-4);
  box-shadow: 0 2px 10px rgba(255, 169, 0, 0.25);
}

.kpi-hint {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-dark);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(32, 38, 46, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px 24px;
  overflow: auto;
}

.modal.hidden {
  display: none !important;
}

body.modal-open {
  overflow: hidden;
}

.modal-box {
  width: min(1080px, 100%);
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--panel-2);
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 16px 20px 20px;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.kpi-value {
  font-family: var(--font);
  font-size: 24px;
  font-weight: 700;
}

.kpi-value.accent { color: var(--accent); }
.kpi-value.green { color: var(--accent-2); }
.kpi-value.red { color: var(--accent-3); }
.kpi-value.amber { color: var(--accent-4); }

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: help;
  max-width: 100%;
  overflow: hidden;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.chart-card canvas {
  width: 100%;
  height: 240px;
}

.split-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.pie-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.pie-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.pie-body {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.pie-svg {
  width: 168px;
  height: 168px;
  flex-shrink: 0;
}

.pie-total {
  font-size: 18px;
  font-weight: 700;
  fill: var(--text);
  font-family: var(--font);
}

.pie-total-label {
  font-size: 9px;
  fill: var(--text-dim);
  font-family: var(--font);
}

.pie-legend {
  list-style: none;
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pie-legend li {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.pie-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.pie-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-legend strong {
  font-variant-numeric: tabular-nums;
}

.pie-pct {
  color: var(--text-dim);
  min-width: 42px;
  text-align: right;
}

.table-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  max-width: 100%;
}

.table-card h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table a.crm-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
}
table a.crm-link:hover {
  text-decoration: underline;
}
.link-sep {
  color: var(--text-dim);
}

.manager-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.manager-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.manager-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}

.manager-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.manager-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.manager-stat span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.manager-stat strong {
  font-size: 16px;
  font-weight: 700;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover td {
  background: var(--panel-2);
}

.bar-row.bar-click {
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 4px;
}
.bar-row.bar-click:hover {
  background: var(--panel-2);
}
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 8px 0 12px;
}
.table-toolbar input[type="search"] {
  min-width: 240px;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}
.table-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
}
button.table-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent-dark);
  cursor: pointer;
  text-align: left;
}
button.table-btn:hover {
  text-decoration: underline;
}

.bar-label {
  width: 240px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-dim);
  white-space: normal;
  line-height: 1.25;
}

.bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg-2);
  border-radius: 6px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  transition: width 0.6s ease;
}

.bar-value {
  width: 80px;
  text-align: right;
  font-weight: 700;
  font-size: 13px;
}

/* ---------- Tooltip ---------- */
.section-title.has-tip,
.bar-row.has-tip,
.pie-legend li.has-tip,
.manager-stat.has-tip,
.table-card.has-tip,
.portal-tile.has-tip {
  cursor: help;
}

.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.tooltip.visible {
  opacity: 1;
}

.tooltip .tt-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.tooltip .tt-desc {
  color: var(--text-dim);
  line-height: 1.4;
}

.howto {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.45;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.portal-tile {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  font-family: var(--font);
}
.portal-tile:hover {
  border-color: var(--accent);
}
.portal-tile strong {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}
.portal-tile span {
  font-size: 11px;
  color: var(--text-dim);
  word-break: break-all;
}

.portal-tile .tile-desc {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-dim);
  word-break: normal;
  margin-bottom: 8px;
}

/* ---------- Responsive ---------- */
.acl-card {
  padding-top: 8px;
}
.acl-status {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 14px;
}
.acl-table th.acl-cell,
.acl-table td.acl-cell {
  text-align: center;
  width: 150px;
  white-space: nowrap;
}
.acl-table td.muted {
  color: var(--text-dim);
}
.acl-check {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 2px solid #c6cdd3;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
  vertical-align: middle;
  position: relative;
}
.acl-check:hover {
  border-color: var(--accent);
}
.acl-check:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.acl-check:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

@media (max-width: 900px) {
  html, body, .app {
    height: auto;
    max-height: none;
    overflow: auto;
  }
  .app {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px;
  }
  .tabs {
    flex-direction: row;
    flex-wrap: wrap;
    flex: none;
    overflow: visible;
  }
  .brand {
    border: none;
    margin: 0;
    padding: 0;
  }
  .sidebar-status {
    display: none;
  }
  .sidebar-footer {
    border: none;
    padding: 0;
    margin: 0 0 0 auto;
    width: 180px;
  }
  .main {
    height: auto;
    overflow: visible;
    padding: 20px;
  }
}
