:root {
  --kkl-bg: #f5f7f8;
  --kkl-surface: #ffffff;
  --kkl-text: #17202a;
  --kkl-muted: #62717f;
  --kkl-border: #dbe3e8;
  --kkl-green: #12805c;
  --kkl-blue: #2268b3;
  --kkl-amber: #b86b00;
  --kkl-red: #b73838;
  --kkl-gray: #687583;
  --kkl-shadow: 0 12px 32px rgba(21, 38, 54, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--kkl-bg);
  color: var(--kkl-text);
  font-family: "Noto Sans Thai", "Sarabun", "Tahoma", system-ui, sans-serif;
  line-height: 1.55;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.kkl-lrt-dashboard {
  width: calc(100% - 32px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 0 44px;
}

.dashboard-header {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #061b36 0%, #0b355b 48%, #0c6b80 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 18px 38px rgba(6, 27, 54, 0.18);
}

.dashboard-header > *,
.panel,
.insight-band > *,
.comment-section,
.comment-tools > * {
  min-width: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-title > div {
  min-width: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.source-label {
  margin: 0 0 4px;
  color: var(--kkl-green);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-header .source-label {
  color: #ffd84d;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(25px, 3.2vw, 38px);
  line-height: 1.15;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.dashboard-header h1 {
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.mobile-title-break {
  display: none;
}

h2 {
  margin-bottom: 4px;
  font-size: 19px;
  line-height: 1.3;
}

.intro {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--kkl-muted);
  overflow-wrap: anywhere;
}

.header-actions,
.tool-controls,
.filter-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.refresh-button,
.filter-button {
  min-height: 40px;
  border: 1px solid var(--kkl-border);
  border-radius: 8px;
  background: #fff;
  color: var(--kkl-text);
  cursor: pointer;
  text-decoration: none;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
}

.refresh-button {
  background: var(--kkl-green);
  border-color: var(--kkl-green);
  color: #fff;
  white-space: nowrap;
}

.dashboard-header .refresh-button {
  background: #ffd84d;
  border-color: #ffd84d;
  color: #08233f;
}

.filter-button:hover {
  border-color: #9fb2bf;
}

.refresh-button:hover {
  background: #0f6f50;
}

.dashboard-header .refresh-button:hover {
  background: #ffe57a;
}

.status-strip {
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid #d8e6dd;
  border-radius: 8px;
  background: #eff8f3;
  color: #215b41;
  font-size: 13px;
  font-weight: 700;
}

.status-strip.is-error {
  background: #fff2f2;
  border-color: #f2cccc;
  color: #8a2a2a;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.view-tabs::-webkit-scrollbar {
  display: none;
}

.tab-button {
  min-height: 38px;
  border: 1px solid var(--kkl-border);
  border-radius: 8px;
  background: #fff;
  color: #41505d;
  cursor: pointer;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.tab-button.is-active {
  background: #e7f2ed;
  border-color: #9fcbb8;
  color: #0f6f50;
}

.summary-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.38fr) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 10px;
  padding: 18px 20px;
  background: #fff;
  border: 1px solid #c7ded2;
  border-radius: 8px;
  box-shadow: var(--kkl-shadow);
}

.summary-label {
  display: block;
  color: var(--kkl-green);
  font-size: 13px;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  margin-top: 2px;
  color: #13202b;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1;
}

.summary-card small {
  display: block;
  margin-top: 6px;
  color: var(--kkl-muted);
  font-weight: 700;
}

.summary-card p {
  margin-bottom: 0;
  color: #26333e;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.6;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.kpi-card,
.panel,
.insight-band,
.comment-section {
  background: var(--kkl-surface);
  border: 1px solid var(--kkl-border);
  border-radius: 8px;
  box-shadow: var(--kkl-shadow);
}

.kpi-card {
  min-height: 112px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card span,
.kpi-card small,
.panel-heading p,
.comment-tools p,
td small {
  color: var(--kkl-muted);
}

.kpi-card strong {
  display: block;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

.kpi-total {
  border-color: #bdd8ca;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 20px;
}

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

.panel-heading p {
  margin-bottom: 0;
  font-size: 13px;
  text-align: right;
  overflow-wrap: anywhere;
}

.donut-layout {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  align-items: center;
  gap: 18px;
}

.donut-chart {
  width: 180px;
  height: 180px;
}

.legend-list {
  display: grid;
  gap: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.bar-chart {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(160px, 0.9fr) minmax(160px, 1.4fr) 46px;
  align-items: center;
  gap: 12px;
  min-height: 34px;
}

.bar-label {
  color: #283642;
  font-size: 14px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #edf2f5;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: var(--kkl-blue);
}

.bar-value {
  text-align: right;
  color: var(--kkl-muted);
  font-weight: 700;
}

.insight-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  margin-top: 14px;
  padding: 22px 24px;
  border-color: #c7ded2;
  background: #fbfefd;
}

.insight-band h2 {
  color: #13202b;
}

.insight-band p,
.insight-band ul {
  margin-bottom: 0;
}

.insight-band ul {
  padding-left: 22px;
}

.comment-section {
  margin-top: 14px;
  padding: 20px;
}

.comment-tools {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(360px, 1.2fr);
  gap: 20px;
  align-items: end;
  margin-bottom: 16px;
}

.search-box {
  display: grid;
  gap: 6px;
  min-width: min(100%, 300px);
  color: var(--kkl-muted);
  font-size: 13px;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--kkl-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--kkl-text);
}

.filter-button.is-active {
  background: #e7f2ed;
  border-color: #9fcbb8;
  color: #0f6f50;
}

.table-wrap {
  max-height: 500px;
  overflow: auto;
  border: 1px solid var(--kkl-border);
  border-radius: 8px;
}

.comment-card-list {
  display: none;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f2f5f7;
  font-size: 13px;
}

td {
  font-size: 14px;
}

.comment-text {
  max-width: 560px;
}

.search-highlight {
  display: inline;
  border-radius: 4px;
  padding: 0 2px;
  background: #fff0a6;
  color: inherit;
  box-shadow: inset 0 0 0 1px rgba(184, 107, 0, 0.18);
}

.badge .search-highlight,
.topic-chip .search-highlight {
  background: rgba(255, 216, 77, 0.72);
  box-shadow: none;
}

.quality-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.quality-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.quality-chip.confidence-high {
  background: #e5f3ed;
  color: var(--kkl-green);
}

.quality-chip.confidence-medium {
  background: #fff3df;
  color: var(--kkl-amber);
}

.quality-chip.confidence-low,
.quality-chip.review {
  background: #fae8e8;
  color: var(--kkl-red);
}

.quality-chip.duplicate {
  background: #edf1f5;
  color: var(--kkl-gray);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.support {
  background: #e5f3ed;
  color: var(--kkl-green);
}

.badge.conditional {
  background: #fff3df;
  color: var(--kkl-amber);
}

.badge.oppose {
  background: #fae8e8;
  color: var(--kkl-red);
}

.badge.unclear {
  background: #edf1f5;
  color: var(--kkl-gray);
}

.topic-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-chip {
  border: 1px solid var(--kkl-border);
  border-radius: 999px;
  padding: 3px 8px;
  color: #3a4a56;
  font-size: 12px;
  background: #fff;
}

@media (max-width: 960px) {
  .dashboard-header,
  .dashboard-grid,
  .insight-band,
  .comment-tools {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .tool-controls {
    justify-content: flex-start;
  }

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

  .kpi-total {
    grid-column: 1 / -1;
  }

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

  .summary-card {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@media (max-width: 700px) {
  .table-wrap {
    display: none;
  }

  .comment-card-list {
    display: grid;
    gap: 10px;
  }

  .comment-card-mobile,
  .empty-card {
    padding: 14px;
    border: 1px solid var(--kkl-border);
    border-radius: 8px;
    background: #fff;
  }

  .comment-card-text {
    margin-bottom: 12px;
    color: #1d2a35;
    font-size: 15px;
    line-height: 1.65;
  }

  .comment-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
  }

  .comment-card-meta small {
    color: var(--kkl-muted);
    font-weight: 700;
  }

  .comment-card-source {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 800;
  }

  .empty-card {
    margin: 0;
    color: var(--kkl-muted);
  }
}

@media (max-width: 560px) {
  .kkl-lrt-dashboard {
    width: calc(100% - 20px);
    padding-top: 12px;
  }

  .dashboard-header {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px;
    padding: 14px;
  }

  .panel,
  .insight-band,
  .comment-section {
    padding: 16px;
  }

  .header-title {
    gap: 12px;
    align-items: flex-start;
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .source-label {
    font-size: 12px;
  }

  h1 {
    font-size: 23px;
  }

  .mobile-title-break {
    display: block;
  }

  .header-actions {
    width: auto;
    justify-content: flex-end;
  }

  .refresh-button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 13px;
  }

  .tool-controls {
    width: 100%;
  }

  .status-strip {
    padding: 7px 10px;
    font-size: 12px;
  }

  .view-tabs {
    gap: 6px;
  }

  .tab-button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 36px;
    padding: 7px 8px;
    font-size: 13px;
    text-align: center;
  }

  .summary-card {
    padding: 16px;
  }

  .summary-card p {
    font-size: 15px;
  }

  .panel-heading {
    display: block;
  }

  .panel-heading p {
    margin-top: 6px;
    text-align: left;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kpi-card {
    min-height: 108px;
    padding: 14px;
  }

  .kpi-card span {
    font-size: 14px;
    line-height: 1.35;
  }

  .kpi-card strong {
    font-size: 34px;
  }

  .bar-row {
    grid-template-columns: 1fr 52px;
    gap: 6px 10px;
  }

  .bar-label {
    grid-column: 1 / -1;
  }

  .filter-buttons {
    width: 100%;
  }

  .filter-button {
    flex: 1 1 130px;
  }
}
