/* ==========================================================================
   RSECO Tools - Themeable Modern Developer & Utility Stylesheet
   ========================================================================== */

:root {
  /* Common typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* LIGHT THEME VARIABLES */
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-muted: #e2e8f0;
  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-active: #3b82f6;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #ffffff;

  --accent-cyan: #0284c7;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

/* DARK THEME VARIABLES */
[data-theme="dark"] {
  --bg-app: #0b0f17;
  --bg-surface: #111827;
  --bg-subtle: #1a2234;
  --bg-muted: #242f45;
  --border-subtle: #1f293d;
  --border-medium: #2d3b55;
  --border-active: #60a5fa;

  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-text: #ffffff;

  --accent-cyan: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

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

html {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top App Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background-color 0.2s, border-color 0.2s;
}

.header-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-main);
}

.brand-icon {
  width: 1.75rem;
  height: 1.75rem;
  color: var(--primary);
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-weight: 700;
  font-size: 1.125rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  letter-spacing: -0.01em;
}

.brand-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--primary);
  border: 1px solid var(--border-subtle);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.brand-subtitle {
  font-size: 0.6875rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  width: 1rem;
  height: 1rem;
  color: var(--text-dim);
}

.search-box input {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.45rem 0.75rem 0.45rem 2.25rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  width: 240px;
  transition: all 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-surface);
  width: 280px;
}

/* Theme Toggle Button */
.icon-button {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-button:hover {
  color: var(--text-main);
  border-color: var(--border-medium);
}

.icon-button svg {
  width: 1.15rem;
  height: 1.15rem;
}

[data-theme="dark"] .theme-icon-sun {
  display: block;
}
[data-theme="dark"] .theme-icon-moon {
  display: none;
}
[data-theme="light"] .theme-icon-sun {
  display: none;
}
[data-theme="light"] .theme-icon-moon {
  display: block;
}

/* App Layout Grid */
.app-layout {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: 260px;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.group-title {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 0.25rem 0.6rem;
  margin-bottom: 0.25rem;
}

.nav-tab {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.nav-tab:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

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

/* Workspace */
.workspace {
  flex: 1;
  padding: 2rem;
  background: var(--bg-app);
  overflow-y: auto;
}

.tool-panel {
  display: none;
}

.tool-panel.active {
  display: block;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.panel-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.panel-header p {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.2rem;
}

.panel-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.quota-pill {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* Common Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-medium);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-subtle);
}

.text-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.text-btn:hover {
  background: var(--bg-muted);
}

/* Throughput Benchmark Specific Styles */
.speed-control-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.field-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 260px;
}

.speed-dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.metric-cell {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.metric-large {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.35rem;
}

.metric-large span:first-child {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--primary);
}

.metric-unit {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-wrap {
  margin-bottom: 1.5rem;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--bg-muted);
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent-cyan) 100%);
  border-radius: 9999px;
  transition: width 0.15s ease;
}

.progress-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.policy-note {
  font-size: 0.75rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border-subtle);
  padding-top: 1rem;
}

/* Editor Grid for JSON / Base64 / URL */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.85rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

textarea {
  width: 100%;
  min-height: 380px;
  padding: 1rem;
  background: var(--bg-surface);
  color: var(--text-main);
  border: none;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  resize: vertical;
}

textarea:focus {
  outline: none;
}

.status-bar {
  padding: 0.4rem 0.85rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  border-top: 1px solid var(--border-subtle);
}

.status-bar.ok {
  background: rgba(16, 185, 129, 0.1);
  color: var(--accent-emerald);
}

.status-bar.error {
  background: rgba(244, 63, 94, 0.1);
  color: var(--accent-rose);
}

/* Generic Form Card */
.form-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.form-card label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-card textarea,
.form-card input[type="text"],
.form-card input[type="number"],
.form-card input[type="datetime-local"],
.form-card select {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  font-size: 0.875rem;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-card textarea:focus,
.form-card input:focus,
.form-card select:focus {
  outline: none;
  border-color: var(--primary);
}

.code-font {
  font-family: var(--font-mono) !important;
}

/* Hash Calculator Specific */
.hash-results-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hash-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm);
}

.hash-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
}

.hash-item input {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  width: 100%;
  font-size: 0.8125rem;
}

/* Timestamp Clock Banner */
.clock-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.75rem;
  text-align: center;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.clock-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.clock-display {
  display: block;
  font-family: var(--font-mono);
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.clock-utc {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.tools-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.result-box {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.85rem;
  font-size: 0.8125rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.result-box strong {
  color: var(--text-muted);
}

.result-box span {
  font-family: var(--font-mono);
  color: var(--text-main);
}

/* Controls row (UUID / options) */
.controls-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex !important;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  margin-bottom: 0 !important;
}

/* Regex Tester */
.regex-input-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
}

.regex-delimiter {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary);
  font-size: 1.15rem;
}

.regex-input-group input {
  border: none !important;
  background: transparent !important;
  padding: 0.45rem 0 !important;
  font-family: var(--font-mono);
}

.regex-tip {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.4rem;
}

.regex-highlights {
  min-height: 120px;
  padding: 0.85rem;
  background: var(--bg-app);
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 0.5rem;
}

.regex-match-badge {
  background: rgba(59, 130, 246, 0.25);
  border: 1px solid var(--primary);
  border-radius: 3px;
  padding: 0.1rem 0.25rem;
  font-weight: 600;
  color: var(--primary);
}

/* Latency & Connectivity Probe */
.endpoint-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.endpoint-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.ep-name {
  display: block;
  font-weight: 600;
  font-size: 0.9375rem;
}

.ep-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.ep-metric {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.ep-val {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

.ep-ms {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Subnet Calculator Table */
.subnet-table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
}

.subnet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.subnet-table th,
.subnet-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.subnet-table th {
  color: var(--text-muted);
  width: 35%;
  font-weight: 500;
}

.subnet-table td {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Text & Word Stats */
.stats-counter-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.counter-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.c-val {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.c-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Naming Case Grid */
.case-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1.25rem;
}

.case-card {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.85rem 1rem;
}

.case-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.case-val-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.case-val-row code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-main);
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  padding: 1.5rem 1.25rem;
  margin-top: auto;
}

.footer-container {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-dim);
}

/* Responsive */
@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: 1rem;
  }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 1rem;
  }
  .nav-group {
    flex-direction: row;
    gap: 0.35rem;
  }
  .group-title {
    display: none;
  }
  .nav-tab {
    white-space: nowrap;
  }
  .editor-grid,
  .tools-split,
  .speed-dashboard,
  .endpoint-grid,
  .case-grid {
    grid-template-columns: 1fr;
  }
  .stats-counter-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .search-box input {
    width: 160px;
  }
}
