/* ========== Token Calculator Tool Page ========== */
.tool-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.tool-header {
  text-align: center;
  margin-bottom: 24px;
}

.tool-header h1 {
  font-size: 32px;
  font-weight: 800;
  color: var(--color-heading);
  margin-bottom: 8px;
}

.tool-header .tool-desc {
  font-size: 16px;
  color: var(--color-muted);
  max-width: 700px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Toolbar */
.tool-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 16px;
  padding: 14px 18px;
  background: var(--color-bg-card);
  border-radius: 12px;
  border: 1px solid var(--color-border);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tool-btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.tool-btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}

.tool-btn-secondary {
  background: #10b981;
  color: #fff;
}

.tool-btn-secondary:hover {
  background: #059669;
}

.tool-btn-outline {
  background: #fff;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.tool-btn-outline:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-primary);
}

.tool-btn-danger {
  background: #ef4444;
  color: #fff;
}

.tool-btn-danger:hover {
  background: #dc2626;
}

.tool-btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.tool-btn-purple {
  background: #8b5cf6;
  color: #fff;
}

.tool-btn-purple:hover {
  background: #7c3aed;
  transform: translateY(-1px);
}

.tool-btn-amber {
  background: #f59e0b;
  color: #fff;
}

.tool-btn-amber:hover {
  background: #d97706;
}

/* Layout: Input + Stats side-by-side */
.tool-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.tool-panel {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
}

.panel-header .panel-actions {
  display: flex;
  gap: 6px;
}

/* Input textarea */
.tool-textarea-wrap textarea {
  width: 100%;
  height: 320px;
  padding: 16px;
  border: none;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  background: #1e1e2e;
  color: #cdd6f4;
  box-sizing: border-box;
  outline: none;
}

.tool-textarea-wrap textarea:focus {
  outline: none;
}

.tool-textarea-wrap textarea::placeholder {
  color: #6c7086;
}

/* Token Highlight Output */
.token-highlight-wrap {
  padding: 16px;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.8;
  word-break: break-all;
  min-height: 80px;
}

.token-highlight-wrap .tok-placeholder {
  color: #9ca3af;
  font-family: var(--font-body);
}

.token-highlight-wrap .tok-zh { color: #e74c3c; }
.token-highlight-wrap .tok-en { color: #2980b9; }
.token-highlight-wrap .tok-num { color: #27ae60; }
.token-highlight-wrap .tok-punct { color: #f39c12; }
.token-highlight-wrap .tok-space { color: #bdc3c7; }
.token-highlight-wrap .tok-boundary {
  display: inline-block;
  width: 1px;
  height: 1em;
  background: #e5e7eb;
  margin: 0 1px;
  opacity: 0.5;
}

/* Stats panel */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.stat-card:nth-child(2n) { border-right: none; }
.stat-card:nth-child(n+5) { border-bottom: none; }

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--color-primary);
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--color-muted);
  font-weight: 500;
  margin-top: 4px;
}

.stat-card.token-stat .stat-value { color: var(--color-primary); }
.stat-card.char-stat .stat-value { color: #8b5cf6; }
.stat-card.word-stat .stat-value { color: #10b981; }
.stat-card.line-stat .stat-value { color: #f59e0b; }
.stat-card.sent-stat .stat-value { color: #ef4444; }
.stat-card.bytes-stat .stat-value { color: #6366f1; }

/* Token Distribution */
.token-distribution {
  padding: 14px 16px;
  border-top: 1px solid var(--color-border);
}

.dist-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 8px;
}

.dist-bar-wrap {
  display: flex;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.dist-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  transition: width 0.2s;
  min-width: 0;
  overflow: hidden;
}

.dist-seg.zh { background: #e74c3c; }
.dist-seg.en { background: #2980b9; }
.dist-seg.num { background: #27ae60; }
.dist-seg.punct { background: #f39c12; }
.dist-seg.space { background: #95a5a6; }

.dist-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--color-text);
}

.dist-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dist-legend-item .dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Cost Table */
.cost-section {
  margin-bottom: 20px;
}

.cost-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 12px;
}

.cost-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px 16px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.cost-controls label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  white-space: nowrap;
}

.cost-controls input[type="number"] {
  width: 90px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  outline: none;
}

.cost-controls input[type="number"]:focus {
  border-color: var(--color-primary);
}

.cost-controls select {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  outline: none;
}

.currency-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #f3f4f6;
  border-radius: 6px;
}

.currency-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: #6b7280;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.currency-btn.active {
  background: #fff;
  color: var(--color-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Model table */
.model-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fff;
}

.model-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.model-table th {
  padding: 10px 12px;
  background: #f8fafc;
  border-bottom: 2px solid var(--color-border);
  font-weight: 700;
  color: var(--color-text);
  text-align: center;
  white-space: nowrap;
}

.model-table td {
  padding: 9px 12px;
  border-bottom: 1px solid #f1f5f9;
  text-align: center;
  vertical-align: middle;
}

.model-table tr:hover td {
  background: #f8fafc;
}

.model-table .model-name {
  font-weight: 700;
  text-align: left;
  color: var(--color-heading);
}

.model-table .model-vendor {
  font-size: 11px;
  color: var(--color-muted);
  display: block;
}

.model-table .price-cell {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-weight: 600;
}

.model-table .price-cache {
  color: #10b981;
}

.model-table .price-normal {
  color: var(--color-text);
}

.model-table .price-output {
  color: #8b5cf6;
}

.model-table .context-cell {
  font-size: 12px;
  color: var(--color-muted);
}

.model-table .cost-cell {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-weight: 700;
  color: var(--color-primary);
}

.model-table .context-bar-wrap {
  width: 80px;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.model-table .context-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.2s;
}

.model-table .context-bar-fill.low { background: #10b981; }
.model-table .context-bar-fill.med { background: #f59e0b; }
.model-table .context-bar-fill.high { background: #ef4444; }

/* Model actions */
.model-actions-cell {
  white-space: nowrap;
}

.model-actions-cell .tool-btn-sm {
  padding: 3px 8px;
  font-size: 11px;
  margin: 0 2px;
}

/* Template library */
.template-section {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  align-items: center;
}

.template-section .tpl-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  white-space: nowrap;
}

.tpl-btn {
  padding: 5px 12px;
  font-size: 12px;
  background: #f3f4f6;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.tpl-btn:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* Info section */
.tool-info {
  margin-top: 24px;
  padding: 20px;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 10px;
}

.tool-info h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 10px;
}

.tool-info p, .tool-info li {
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.7;
}

.tool-info ul {
  padding-left: 20px;
  margin: 8px 0;
}

.tool-info li {
  margin-bottom: 4px;
}

/* Add/Edit model modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-heading);
  margin-bottom: 16px;
}

.modal-field {
  margin-bottom: 12px;
}

.modal-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  margin-bottom: 4px;
}

.modal-field input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  box-sizing: border-box;
}

.modal-field input:focus {
  border-color: var(--color-primary);
}

.modal-field .field-hint {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* Responsive */
@media (max-width: 900px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .stat-card:nth-child(3n) { border-right: none; }
  .stat-card:nth-child(n+4) { border-bottom: 1px solid var(--color-border); }
  .stat-card:nth-child(n+4):nth-child(-n+6) { border-bottom: none; }
}

@media (max-width: 600px) {
  .tool-container { padding: 12px; }
  .tool-header h1 { font-size: 22px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card .stat-value { font-size: 24px; }
  .stat-card:nth-child(2n) { border-right: none; }
  .stat-card:nth-child(n+3) { border-bottom: 1px solid var(--color-border); }
  .stat-card:nth-child(5), .stat-card:nth-child(6) { border-bottom: none !important; }
  .tool-toolbar { padding: 10px; gap: 6px; }
  .tool-btn { padding: 8px 14px; font-size: 13px; }
  .cost-controls { flex-direction: column; align-items: stretch; }
  .model-table { font-size: 12px; }
  .model-table th, .model-table td { padding: 6px 8px; }
  .template-section { flex-direction: column; align-items: stretch; }
}

/* Status */
.status-box {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
  display: none;
  line-height: 1.5;
}

.status-box.show { display: block; }
.status-box.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.status-box.success { background: #f0fdf4; color: #065f46; border: 1px solid #bbf7d0; }
.status-box.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Empty state for model table */
.empty-models {
  text-align: center;
  padding: 30px;
  color: #9ca3af;
  font-size: 14px;
}