:root {
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #171b21;
  --border: #282e37;
  --text: #f4f5f7;
  --muted: #9199a6;
  --accent: #e6b84a;
  --danger: #e46f6f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

.topbar {
  height: 70px;
  padding: 0 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 900;
  letter-spacing: 2px;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
}

.language-button {
  justify-self: end;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.shell {
  width: min(1000px, calc(100% - 32px));
  margin: 0 auto;
  padding: 42px 0 80px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 1.5px;
}

h1, h2 { margin-top: 0; }

.muted {
  color: var(--muted);
  line-height: 1.5;
}

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

.page-heading h1 {
  margin: 6px 0;
}

.heading-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.primary-link,
.ghost-link,
.danger-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button,
.primary-link {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #181308;
}

.ghost-button,
.ghost-link {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.danger-button {
  border: 1px solid rgba(228,111,111,.45);
  background: rgba(228,111,111,.05);
  color: #efa5a5;
}

.primary-link,
.ghost-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.status-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}

.status-card {
  max-width: 650px;
  margin: 40px auto;
  padding: 24px;
}

.sync-note {
  margin: 18px 0;
  padding: 11px 13px;
  border: 1px solid rgba(230,184,74,.25);
  border-radius: 9px;
  background: rgba(230,184,74,.035);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.panel {
  margin-top: 16px;
  padding: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

label > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 1px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f1216;
  color: var(--text);
}

textarea {
  min-height: 80px;
  padding-top: 9px;
}

.input-unit {
  display: grid;
  grid-template-columns: 1fr auto;
}

.input-unit input {
  border-radius: 8px 0 0 8px;
}

.input-unit span {
  min-width: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

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

.message.error { color: #efa5a5; }

.history-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.history-card {
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0f1216;
}

.history-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-top strong {
  font-size: 18px;
}

.history-source {
  margin-top: 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.history-actions {
  margin-top: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;

  display: grid;
  place-items: center;

  padding: 16px;

  background:
    rgba(0,0,0,.78);
}

.modal-card {
  width: min(900px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;

  padding: 20px;

  border: 1px solid var(--border);
  border-radius: 14px;

  background: var(--bg);
}

.calibration-card {
  margin-top: 15px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.calibration-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 10px;
}

#scaleValue {
  min-width: 60px;
  text-align: center;
  color: var(--accent);
  font-weight: 850;
}

.reference-wrap {
  margin-top: 14px;
  overflow-x: auto;
}

.reference-bar {
  height: 12px;
  border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
}

#referenceLabel {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.ruler-instructions {
  margin: 15px 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.ruler-scroll {
  overflow-x: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f5f3eb;
}

#rulerCanvas {
  display: block;
  touch-action: none;
}

.ruler-result {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 14px;
}

.ruler-result span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 1px;
}

.ruler-result strong {
  color: var(--accent);
  font-size: 26px;
}

.ruler-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 700px) {
  .page-heading,
  .panel-heading,
  .modal-heading {
    flex-direction: column;
  }

  .heading-actions {
    width: 100%;
  }

  .heading-actions > * {
    flex: 1;
    justify-content: center;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .full {
    grid-column: auto;
  }

  .modal {
    padding: 6px;
  }

  .modal-card {
    max-height: calc(100vh - 12px);
    padding: 14px;
  }

  .ruler-actions {
    flex-direction: column;
  }
}
