:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6472;
  --line: #dbe4ef;
  --primary: #1d4ed8;
  --focus: #93c5fd;
  --safe: #16a34a;
  --moderate: #d97706;
  --high: #dc2626;
  --critical: #7f1d1d;
}

body.dark {
  --bg: #090f1d;
  --card: #121a2d;
  --text: #e5ecf7;
  --muted: #95a2bb;
  --line: #27334a;
  --primary: #3b82f6;
  --focus: #1d4ed8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.28s ease, color 0.28s ease;
}

.wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.chip-btn,
.button-group button,
.tool-toggle-btn,
.copy-btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chip-btn:hover,
.button-group button:hover,
.tool-toggle-btn:hover,
.copy-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.chip-btn:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

.hidden {
  display: none !important;
}

.battery-tool {
  display: grid;
  gap: 12px;
}

.hero,
.panel,
.sticky-risk {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.hero h1 {
  margin: 0 0 4px;
  font-size: 1.55rem;
}

.hero p {
  margin: 0;
  color: var(--muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

select,
input[type="range"],
textarea {
  width: 100%;
}

select {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
}

.input-group output {
  display: inline-block;
  margin-top: 4px;
  font-weight: 600;
  color: var(--primary);
}

.tip {
  display: block;
  margin-top: 2px;
  min-height: 1.2em;
  color: var(--high);
  font-size: 0.83rem;
}

.sticky-risk {
  position: sticky;
  top: 8px;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.risk-result {
  border-radius: 12px;
  padding: 12px;
  min-height: 72px;
  font-weight: 600;
  transition: all 0.25s ease;
}

.risk-safe { background: #dcfce7; color: #14532d; }
.risk-moderate { background: #fef3c7; color: #78350f; }
.risk-high { background: #fee2e2; color: #7f1d1d; }
.risk-critical { background: #fecaca; color: #450a0a; }
body.dark .risk-safe { background: #052e1b; color: #bbf7d0; }
body.dark .risk-moderate { background: #422006; color: #fde68a; }
body.dark .risk-high { background: #450a0a; color: #fecaca; }
body.dark .risk-critical { background: #3b0606; color: #fecaca; }

.battery-gauge {
  display: flex;
  align-items: center;
  gap: 4px;
}

.battery-shell {
  width: 62px;
  height: 28px;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 2px;
}

.battery-cap {
  width: 4px;
  height: 14px;
  background: var(--line);
  border-radius: 0 2px 2px 0;
}

.battery-fill {
  height: 100%;
  width: 20%;
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
  background: var(--safe);
}

.battery-fill.pulse {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.05); }
}

.tips-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.history-head h3 {
  margin: 0;
}

.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.92rem;
}

th,
td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: center;
}

th {
  background: rgba(93, 126, 170, 0.1);
}

.risk-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  color: #fff;
  font-weight: 700;
}

.history-delete-btn {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #b91c1c;
  border-radius: 10px;
  padding: 6px 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.history-delete-btn:hover {
  background: #ef4444;
  color: #ffffff;
  transform: translateY(-1px);
}

body.dark .history-delete-btn {
  background: #3f0d0d;
  border-color: #7f1d1d;
  color: #fecaca;
}

body.dark .history-delete-btn:hover {
  background: #dc2626;
  color: #ffffff;
}

.tool-extra-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.popup-overlay,
.legal-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.56);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.popup-overlay.active,
.legal-popup-overlay.active {
  display: flex;
}

.popup-box,
.legal-popup-box {
  width: min(760px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  position: relative;
}

.popup-close {
  position: absolute;
  right: 12px;
  top: 12px;
}

textarea {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  padding: 10px;
}

.skeleton {
  background: linear-gradient(90deg, rgba(148, 163, 184, 0.16), rgba(148, 163, 184, 0.06), rgba(148, 163, 184, 0.16));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (max-width: 820px) {
  .grid-2,
  .sticky-risk {
    grid-template-columns: 1fr;
  }

  .history-head {
    flex-direction: column;
  }

  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
  }

  td {
    display: flex;
    justify-content: space-between;
    text-align: left;
    border: 0;
    border-bottom: 1px solid var(--line);
  }
}
