/* ==========================================================================
   LocalTools - visual system
   Dev-tool-native: flat surfaces, hairline borders, mono-forward data,
   one accent, tight radii, restrained motion. Light default, dark via
   prefers-color-scheme. No web fonts / no dependencies (offline-friendly).
   Logic, IDs and data hooks live in app.js and are not touched here.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "SFMono-Regular", "Menlo", "Consolas",
    "Liberation Mono", monospace;

  /* spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;

  /* radii (3 steps, deliberately tight) */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;

  /* dark palette (default) - warm charcoal for the black-gold look */
  --bg: #121110;
  --surface: #1a1816;
  --surface-2: #201d19;
  --surface-inset: #161412;
  --border: #2c2823;
  --border-strong: #3b352d;
  --text: #ece9e3;
  --text-muted: #a39d92;
  --text-faint: #726c61;

  --accent: #c8a55e;
  --accent-hover: #dcbb74;
  --accent-weak: rgba(200, 165, 94, 0.16);
  --accent-on: #18140a;

  --success: #4cbf97;
  --error: #e07c6f;

  /* json syntax */
  --syn-key: #d6a06a;
  --syn-string: #6cc7a3;
  --syn-number: #7fb3e6;
  --syn-boolean: #d188bd;
  --syn-null: #7c857f;

  --overlay-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  --focus-ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);

  --maxw: 1240px;
  --rail: clamp(312px, 27%, 360px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
p {
  margin: 0;
}

.page-shell {
  width: min(var(--maxw), calc(100vw - 48px));
  margin: 0 auto;
  padding: var(--sp-7) 0 var(--sp-8);
}

.grid {
  display: block;
}

/* --------------------------------------------------------------------------
   Top navigation (tab bar)
   Underline-style nav, not a floating gradient pill bar.
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

.tab-bar {
  display: flex;
  gap: var(--sp-1);
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  box-shadow: none;
}

.tab-button {
  position: relative;
  appearance: none;
  border: 0;
  border-radius: 0;
  padding: var(--sp-3) var(--sp-3);
  background: transparent;
  color: var(--text-muted);
  font: 500 14px/1.2 var(--font-sans);
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: color 140ms ease;
}

.tab-button::after {
  content: "";
  position: absolute;
  left: var(--sp-3);
  right: var(--sp-3);
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.tab-button.active {
  color: var(--text);
  font-weight: 600;
}

.tab-button.active::after {
  opacity: 1;
  transform: scaleX(1);
}

/* --------------------------------------------------------------------------
   Panels / surfaces
   Flat. Hairline border, no blur, no floaty shadow. Cards earn elevation
   only when they overlay (fullscreen). Default grouping = border + spacing.
   -------------------------------------------------------------------------- */
.panel {
  padding: var(--sp-6);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: none;
}

.tab-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-5);
  animation: panel-in 220ms ease both;
}

.tab-panel[hidden] {
  display: none;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.time-panel {
  grid-column: 1 / -1;
}

/* JSON tab: main editor with a history rail on the right; favorites sits
   directly under the formatter card in the main column. */
#panel-json-format {
  grid-template-columns: minmax(0, 1fr) var(--rail);
  align-items: start;
}

#panel-json-format > .tool-panel:nth-child(1) {
  grid-column: 1;
  grid-row: 1;
}

#panel-json-format > .tool-panel:nth-child(2) {
  grid-column: 2;
  grid-row: 1;
}

#panel-json-format > .tool-panel:nth-child(3) {
  grid-column: 1;
  grid-row: 2;
}

/* Rail panels read as secondary: lighter ground, quieter titles. */
#panel-json-format > .tool-panel:not(.full-width) {
  background: var(--surface-2);
  padding: var(--sp-5);
}

#panel-json-format > .tool-panel:not(.full-width) .panel-header h2 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

h2 {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
}

.split-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}

.split-column {
  min-width: 0;
}

/* --------------------------------------------------------------------------
   Labels & status badge
   -------------------------------------------------------------------------- */
.input-label,
.label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.input-label {
  margin-bottom: var(--sp-2);
}

.input-header,
.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 34px;
  margin-bottom: var(--sp-2);
}

.input-header .input-label,
.output-header .input-label {
  margin-bottom: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--r-xs);
  font: 600 11px/1 var(--font-mono);
  letter-spacing: 0.08em;
}

.live {
  color: var(--accent);
  background: var(--accent-weak);
}

.live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

/* --------------------------------------------------------------------------
   Time readouts (flat cells, mono tabular figures)
   -------------------------------------------------------------------------- */
.time-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--sp-3);
}

.time-convert-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-3);
}

.time-card {
  position: relative;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.time-card .label {
  padding-right: 56px;
}

.value {
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: clamp(16px, 1.5vw, 21px);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.convert-result {
  font-size: clamp(15px, 1.3vw, 19px);
}

/* --------------------------------------------------------------------------
   Editors / output surfaces
   -------------------------------------------------------------------------- */
.json-output-shell {
  position: relative;
}

.json-output-shell .json-tree {
  height: var(--json-editor-height, auto);
}

#json-object-output {
  height: var(--json-string-editor-height, auto);
}

.editor,
.object-view,
.json-tree {
  width: 100%;
  min-height: 480px;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: 13px/1.65 var(--font-mono);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.editor.compact {
  min-height: 132px;
}

.editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

#json-input,
#json-string-input {
  resize: vertical;
}

.output,
.object-view,
.json-tree {
  background: var(--surface-inset);
}

.object-view,
.json-tree {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.json-tree {
  font: 13px/1.7 var(--font-mono);
}

.json-tree.empty {
  display: flex;
  align-items: center;
  color: var(--text-faint);
}

.json-line {
  min-height: 1.7em;
}

.json-toggle {
  appearance: none;
  width: 20px;
  margin-right: var(--sp-1);
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  user-select: none;
}

.json-toggle::before {
  content: attr(data-symbol);
}

.json-key {
  color: var(--syn-key);
}

.json-string {
  color: var(--syn-string);
}

.json-number {
  color: var(--syn-number);
}

.json-boolean {
  color: var(--syn-boolean);
}

.json-null {
  color: var(--syn-null);
}

/* Fullscreen JSON output (the one place real elevation belongs). */
.json-output-shell:fullscreen {
  display: flex;
  padding: var(--sp-5);
  background: var(--bg);
}

.json-output-shell:fullscreen .json-tree {
  min-height: auto;
  height: 100%;
}

.json-output-shell.is-fullscreen-fallback {
  position: fixed;
  inset: var(--sp-5);
  z-index: 100;
  display: flex;
  padding: var(--sp-5);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  box-shadow: var(--overlay-shadow);
}

.json-output-shell.is-fullscreen-fallback .json-tree {
  min-height: auto;
  height: 100%;
}

body.json-fullscreen-active {
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Buttons
   Solid accent for primary, no gradients, tactile press.
   -------------------------------------------------------------------------- */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin: var(--sp-5) 0 var(--sp-3);
}

.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  font: 500 13px/1 var(--font-sans);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease,
    transform 80ms ease;
}

.button:active {
  transform: translateY(1px);
}

.icon-button {
  padding: var(--sp-2) var(--sp-3);
  white-space: nowrap;
}

.primary {
  color: var(--accent-on);
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-hover);
}

.secondary {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.secondary:hover {
  background: var(--surface-inset);
  border-color: var(--border-strong);
}

.ghost {
  color: var(--text-muted);
  background: transparent;
  border-color: var(--border);
}

.ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   Copy buttons on time cards
   -------------------------------------------------------------------------- */
.card-copy-button {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: var(--sp-1) var(--sp-2);
  background: var(--surface);
  color: var(--text-muted);
  font: 500 11px/1 var(--font-sans);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease,
    transform 80ms ease;
}

.card-copy-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.card-copy-button:active {
  transform: translateY(1px);
}

.card-copy-button.copied {
  color: var(--accent);
  background: var(--accent-weak);
  border-color: transparent;
}

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */
.message {
  min-height: 20px;
  margin-bottom: var(--sp-3);
  font-size: 13px;
  color: var(--text-muted);
}

.message.success {
  color: var(--success);
}

.message.error {
  color: var(--error);
}

/* --------------------------------------------------------------------------
   History / favorites records
   -------------------------------------------------------------------------- */
.record-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.record-list.empty {
  justify-content: center;
  min-height: 88px;
  padding: var(--sp-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text-faint);
  font-size: 13px;
}

.record-item {
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
}

/* Single row that always fits the history rail: full timestamp plus
   compact actions, neither wraps. */
.record-meta {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.record-time {
  flex-shrink: 0;
  white-space: nowrap;
  color: var(--text-faint);
  font: 12px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.record-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: nowrap;
  gap: var(--sp-1);
}

.record-button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: var(--sp-1) var(--sp-2);
  background: var(--surface-2);
  color: var(--text);
  font: 500 12px/1.4 var(--font-sans);
  white-space: nowrap;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 80ms ease;
}

.record-button:hover {
  border-color: var(--border-strong);
}

.record-button:active {
  transform: translateY(1px);
}

.record-preview {
  margin: 0;
  max-height: 152px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  font: 12px/1.6 var(--font-mono);
}

/* --------------------------------------------------------------------------
   Focus visibility (keyboard a11y)
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.editor:focus-visible,
.object-view:focus-visible {
  outline: none;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  #panel-json-format {
    grid-template-columns: 1fr;
  }

  #panel-json-format > .tool-panel:nth-child(1),
  #panel-json-format > .tool-panel:nth-child(2),
  #panel-json-format > .tool-panel:nth-child(3) {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 900px) {
  .tab-panel {
    grid-template-columns: 1fr;
  }

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

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

  .time-convert-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 24px, var(--maxw));
    padding-top: var(--sp-5);
  }

  .panel {
    padding: var(--sp-4);
  }

  .time-cards {
    grid-template-columns: 1fr;
  }

  .tab-bar {
    gap: 0;
    overflow-x: auto;
  }

  .tab-button {
    white-space: nowrap;
  }

  .actions {
    flex-direction: column;
  }

  .actions .button {
    width: 100%;
  }

  .output-header {
    align-items: stretch;
    flex-direction: column;
  }

  .icon-button {
    width: 100%;
  }

  .json-output-shell.is-fullscreen-fallback {
    inset: var(--sp-3);
    padding: var(--sp-3);
  }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
