/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f5f5f5; color: #333; line-height: 1.5; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #f5f5f5; }
.login-box { background: #fff; padding: 2rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); width: 100%; max-width: 400px; text-align: center; }
.login-box h1 { margin-bottom: 0.5rem; font-size: 1.5rem; }
.login-box p { color: #666; margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-box input { width: 100%; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; font-family: monospace; margin-bottom: 1rem; }
.login-box button { width: 100%; padding: 0.75rem; background: #2563eb; color: #fff; border: none; border-radius: 4px; font-size: 1rem; cursor: pointer; }
.login-box button:hover { background: #1d4ed8; }

/* Header */
header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 2rem; background: #fff; border-bottom: 1px solid #e5e5e5; }
.header-left h1 { font-size: 1.25rem; }
.header-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.header-credits { font-weight: 600; font-size: 0.85rem; color: #2563eb; }
.header-credits.credits-low { color: #dc2626; }
.header-divider { width: 1px; height: 20px; background: #e5e5e5; }

/* Navigation */
nav { display: flex; gap: 0; background: #fff; border-bottom: 1px solid #e5e5e5; padding: 0 2rem; }
.tab { padding: 0.75rem 1.25rem; border: none; background: none; cursor: pointer; font-size: 0.9rem; color: #666; border-bottom: 2px solid transparent; }
.tab:hover { color: #333; }
.tab.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 500; }

/* Sections */
.section { padding: 2rem; max-width: 1200px; margin: 0 auto; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section h2 { font-size: 1.25rem; margin-bottom: 1rem; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: #fff; padding: 1.25rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); text-align: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: #2563eb; }
.stat-label { font-size: 0.8rem; color: #888; margin-top: 0.25rem; }

/* Key Info Card */
.key-info-card { background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.key-info-row { padding: 0.5rem 0; border-bottom: 1px solid #f0f0f0; display: flex; gap: 1rem; }
.key-info-row:last-child { border-bottom: none; }
.key-info-label { font-weight: 500; min-width: 120px; color: #666; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid #f0f0f0; font-size: 0.9rem; }
th { background: #fafafa; font-weight: 600; color: #555; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafafa; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

/* Buttons */
.btn { padding: 0.5rem 1rem; border-radius: 4px; border: none; cursor: pointer; font-size: 0.875rem; font-weight: 500; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: #fff; border: 1px solid #ddd; color: #333; }
.btn-outline:hover { background: #f5f5f5; }

/* Forms */
fieldset { border: 1px solid #e5e5e5; border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.5rem; color: #555; }
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: #555; margin-bottom: 0.25rem; }
.form-group input, .form-group select { width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 0.9rem; }
.form-group input[type="file"] { padding: 0.4rem; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.checkbox-label { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 1rem; margin-bottom: 0.5rem; font-size: 0.85rem; cursor: pointer; }
.checkbox-grid { display: flex; flex-wrap: wrap; margin-bottom: 0.5rem; }

/* Filters */
.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filters input, .filters select { padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 0.85rem; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }

/* Config Card */
.config-card { background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); max-width: 600px; }
.config-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 0; border-bottom: 1px solid #f0f0f0; }
.config-row:last-child { border-bottom: none; }
.config-label { font-weight: 500; min-width: 180px; color: #555; }
.config-row input[type="number"] { width: 100px; padding: 0.4rem; border: 1px solid #ddd; border-radius: 4px; }
.config-hint { font-size: 0.85rem; color: #888; margin: 0 0 0.5rem; }
.config-cost-unit { font-size: 0.85rem; color: #888; }

/* Toggle Switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: 0.2s; }
.toggle-slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.toggle input:checked + .toggle-slider { background: #2563eb; }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Credit Preview */
.credit-preview { background: #fffbeb; border: 1px solid #fde68a; padding: 0.75rem 1rem; border-radius: 4px; margin-top: 1rem; font-size: 0.9rem; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: #fff; padding: 2rem; border-radius: 8px; max-width: 500px; width: 90%; }
.modal-content h3 { margin-bottom: 0.75rem; }
.key-display { font-family: monospace; background: #f5f5f5; padding: 1rem; border-radius: 4px; margin: 1rem 0; word-break: break-all; font-size: 0.9rem; user-select: all; }

/* Toast */
.toast { position: fixed; bottom: 2rem; right: 2rem; background: #333; color: #fff; padding: 0.75rem 1.5rem; border-radius: 6px; font-size: 0.9rem; z-index: 200; transition: opacity 0.3s; max-width: 500px; line-height: 1.4; }
.toast.toast-error { background: #dc2626; }
.toast.toast-success { background: #16a34a; }

/* Error */
.error { color: #dc2626; font-size: 0.85rem; margin-top: 0.5rem; }

/* Form Card */
.form-card { background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-top: 1rem; margin-bottom: 1rem; }

/* Section Header h2 */
.section-header h2 { margin-bottom: 0; }

/* Modal button spacing */
.modal-content .btn { margin-right: 0.5rem; }

/* Table action button alignment */
td .btn { margin-right: 0.25rem; margin-bottom: 0.25rem; }

/* Empty state */
.empty-state { text-align: center; padding: 2rem; color: #888; font-size: 0.9rem; }

/* Search bar */
.search-bar { display: flex; gap: 0.75rem; margin-bottom: 1rem; align-items: center; }
.search-bar input { flex: 1; max-width: 300px; padding: 0.5rem 0.75rem; border: 1px solid #ddd; border-radius: 4px; font-size: 0.9rem; }
.search-bar select { padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 0.85rem; }

/* Expandable features */
.features-toggle { color: #2563eb; cursor: pointer; font-size: 0.85rem; text-decoration: underline; }
.features-detail { margin-top: 0.5rem; padding: 0.75rem; background: #f9fafb; border-radius: 4px; font-size: 0.8rem; }
.features-detail .feature-group { margin-bottom: 0.5rem; }
.features-detail .feature-group-title { font-weight: 600; color: #555; margin-bottom: 0.25rem; }
.features-detail .feature-item { display: inline-block; background: #e5e7eb; padding: 0.1rem 0.4rem; border-radius: 3px; margin: 0.1rem; font-size: 0.75rem; color: #374151; }

/* Loading indicator */
.loading { text-align: center; padding: 1.5rem; color: #888; }
.loading::after { content: '...'; animation: dots 1s steps(3) infinite; }
@keyframes dots { 0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; } }

/* Table wrapper */
.table-wrapper { overflow-x: auto; border-radius: 8px; }

/* Panel card — wraps search + table into one visual group */
.panel-card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); padding: 1.25rem; margin-bottom: 1.5rem; }
.panel-card .search-bar { margin-bottom: 0.75rem; }
.panel-card .table-wrapper { margin: 0 -1.25rem; }
.panel-card .table-wrapper table { border-radius: 0; box-shadow: none; }
.panel-card .pagination { margin-top: 0.75rem; }

/* Utility */
.hidden { display: none !important; }

/* Large modal for forms */
.modal-large { max-width: 700px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 1rem; border-bottom: 1px solid #e5e5e5; margin-bottom: 1rem; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #888; padding: 0 0.25rem; line-height: 1; }
.modal-close:hover { color: #333; }
.modal-body { overflow-y: auto; flex: 1; }

/* Optimistic delete fade-out */
tr.deleting { opacity: 0.3; pointer-events: none; transition: opacity 0.2s; }
tr.deleted { display: none; }

/* Clickable table elements */
.clickable { cursor: pointer; color: #2563eb; }
.clickable:hover { text-decoration: underline; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #eef2ff !important; }

/* Detail view */
.detail-grid { display: flex; flex-direction: column; gap: 0; }
.detail-row { display: flex; padding: 0.6rem 0; border-bottom: 1px solid #f0f0f0; }
.detail-row:last-child { border-bottom: none; }
.detail-label { font-weight: 500; min-width: 120px; color: #666; flex-shrink: 0; }
.detail-error span { color: #dc2626; }
.detail-json { background: #f5f5f5; padding: 1rem; border-radius: 4px; font-size: 0.8rem; font-family: monospace; overflow-x: auto; white-space: pre; margin: 0; max-height: 300px; overflow-y: auto; }

/* Back button */
.btn-back { font-size: 0.9rem; }

/* Sub-tabs */
.sub-tabs { display: flex; gap: 0; border-bottom: 1px solid #e5e5e5; margin-bottom: 1rem; }
.sub-tab { padding: 0.6rem 1rem; border: none; background: none; cursor: pointer; font-size: 0.85rem; color: #666; border-bottom: 2px solid transparent; }
.sub-tab:hover { color: #333; }
.sub-tab.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 500; }

/* Key detail sections */
.kd-section { }

/* Docs */
.docs-category-nav { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.docs-category-btn { padding: 0.4rem 0.8rem; border: 1px solid #e5e5e5; border-radius: 16px; background: #fff; cursor: pointer; font-size: 0.8rem; color: #555; transition: all 0.15s; }
.docs-category-btn:hover { border-color: #2563eb; color: #2563eb; }
.docs-category-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.docs-category-btn .cat-count { font-size: 0.7rem; opacity: 0.7; margin-left: 0.25rem; }

.docs-endpoint-card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); padding: 1.5rem; margin-bottom: 1rem; }
.docs-endpoint-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.docs-method { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 4px; font-size: 0.75rem; font-weight: 700; font-family: monospace; letter-spacing: 0.03em; }
.docs-method-GET { background: #dcfce7; color: #166534; }
.docs-method-POST { background: #dbeafe; color: #1e40af; }
.docs-method-PATCH { background: #fef3c7; color: #92400e; }
.docs-method-DELETE { background: #fee2e2; color: #991b1b; }
.docs-path { font-family: monospace; font-size: 1rem; font-weight: 600; }
.docs-summary { font-size: 0.9rem; color: #666; margin-bottom: 0.25rem; }
.docs-description { font-size: 0.9rem; color: #555; margin-bottom: 1rem; line-height: 1.6; }
.docs-section-title { font-size: 0.85rem; font-weight: 600; color: #333; margin: 1rem 0 0.5rem; }
.docs-note { font-size: 0.85rem; color: #666; font-style: italic; margin-top: 0.75rem; }
.docs-param-unavailable { opacity: 0.45; font-style: italic; }

.docs-code-block { position: relative; background: #1e1e2e; color: #cdd6f4; padding: 1rem; border-radius: 6px; font-family: monospace; font-size: 0.8rem; overflow-x: auto; white-space: pre; margin: 0.5rem 0; line-height: 1.5; }
.docs-code-block .copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; background: rgba(255,255,255,0.1); border: none; color: #cdd6f4; padding: 0.25rem 0.5rem; border-radius: 4px; cursor: pointer; font-size: 0.7rem; }
.docs-code-block .copy-btn:hover { background: rgba(255,255,255,0.2); }

.docs-category-heading { font-size: 1.1rem; font-weight: 600; color: #333; margin: 2rem 0 1rem; padding-bottom: 0.5rem; border-bottom: 1px solid #e5e5e5; }
.docs-category-heading:first-child { margin-top: 0; }

.docs-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 768px) { .docs-columns { grid-template-columns: 1fr; } }

/* Responsive */
@media (max-width: 768px) {
    header { flex-direction: column; gap: 0.5rem; padding: 1rem; }
    .section { padding: 1rem; }
    nav { overflow-x: auto; padding: 0 1rem; }
    table { display: block; overflow-x: auto; }
    .form-row { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
