/* Base Styles */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --warning-color: #f59e0b;
    --success-color: #10b981;
    --bg-color: #f8fafc;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-muted: #64748b;
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--bg-color);
}

/* Page Layout */
.page {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-shrink: 0;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-info {
    margin-right: 1rem;
    color: var(--text-muted);
}

.content {
    padding: 2rem;
    flex: 1;
}

/* Navigation */
.nav-menu {
    padding: 1rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.brand-text {
    font-size: 1.25rem;
    font-weight: 600;
}

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

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.nav-link:hover {
    background: rgba(255,255,255,0.1);
}

.nav-link.active {
    background: var(--primary-color);
}

.nav-icon {
    width: 1rem;
    height: 1rem;
    margin-right: 0.75rem;
    flex-shrink: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    gap: 0.5rem;
}

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

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

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

.btn-secondary {
    background: #e2e8f0;
    color: var(--text-color);
}

.btn-secondary:hover:not(:disabled) {
    background: #cbd5e1;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

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

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-block {
    width: 100%;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-logout:hover {
    background: var(--bg-color);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.required {
    color: var(--danger-color);
}

.text-danger {
    color: var(--danger-color);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Cards */
.card, .settings-card, .setup-card, .login-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 120px);
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    margin-bottom: 0.5rem;
}

.login-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Setup Page */
.setup-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 120px);
}

.setup-card {
    width: 100%;
    max-width: 500px;
}

.setup-card h1 {
    margin-bottom: 0.5rem;
}

.setup-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.api-key-display .warning {
    color: var(--danger-color);
    font-weight: 500;
    margin-bottom: 1rem;
}

.api-key-box {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.api-key-box code {
    flex: 1;
    font-family: 'Consolas', monospace;
    font-size: 0.875rem;
    word-break: break-all;
}

.btn-copy {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
}

.checkbox-confirm {
    margin: 1rem 0;
}

/* Dashboard */
.dashboard h1 {
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-icon {
    width: 1.5rem;
    height: 1.5rem;
    stroke: var(--primary-color);
    flex-shrink: 0;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.quick-actions {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.quick-actions h2 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.api-info {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.api-info h2 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.endpoint-box {
    background: #f1f5f9;
    padding: 1rem;
    border-radius: 0.5rem;
}

.endpoint-box code {
    font-family: 'Consolas', monospace;
    font-size: 1rem;
    color: var(--primary-color);
}

.endpoint-box p {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    display: block;
}

.back-link:hover {
    color: var(--primary-color);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.empty-icon {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 1rem;
    stroke: var(--text-muted);
}

.empty-state h2 {
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.filter-select {
    width: auto;
    min-width: 150px;
}

.search-input {
    flex: 1;
    max-width: 300px;
}

/* Data Table */
.table-container {
    background: var(--card-bg);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.data-table code {
    background: #f1f5f9;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
}

.row-inactive {
    opacity: 0.6;
}

.row-expired td {
    background: #fef2f2;
}

.row-warning td {
    background: #fffbeb;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

.badge-active {
    background: #dcfce7;
    color: #166534;
}

.badge-inactive {
    background: #e2e8f0;
    color: #475569;
}

.badge-expired {
    background: #fecaca;
    color: #991b1b;
}

.badge-warning {
    background: #fde68a;
    color: #92400e;
}

/* Actions */
.actions {
    white-space: nowrap;
}

.btn-action {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.btn-action:hover {
    background: #e2e8f0;
}

.btn-action.delete:hover {
    background: #fecaca;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-dialog {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    max-width: 400px;
    width: 90%;
}

.modal-dialog h3 {
    margin-bottom: 1rem;
}

.modal-dialog .hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* Form Container */
.form-container {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    max-width: 600px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Key Info */
.key-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    padding: 1rem;
    background: #f8fafc;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.key-info .label {
    color: var(--text-muted);
}

/* Settings */
.settings-container {
    max-width: 800px;
}

.settings-card {
    margin-bottom: 1.5rem;
}

.settings-card h2 {
    margin-bottom: 0.5rem;
}

.settings-card > p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.api-key-info {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

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

.info-row:last-child {
    margin-bottom: 0;
}

.info-row .label {
    color: var(--text-muted);
}

.new-key-display {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.regenerate-section {
    margin-top: 1rem;
}

.confirm-box {
    background: #fef2f2;
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid #fecaca;
}

.confirm-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* API Docs */
.api-docs-section {
    background: var(--card-bg);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-top: 2rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.api-docs-section h2 {
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

.api-docs h3 {
    margin-bottom: 1rem;
}

.api-docs h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 1.5rem 0 0.5rem;
}

.api-docs pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    font-size: 0.8125rem;
}

.api-docs pre code {
    background: none;
    padding: 0;
}

/* Password Change Section */
.password-change-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
}

.password-change-section h3 {
    margin-bottom: 0.5rem;
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .content {
        padding: 1rem;
    }

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

    .filter-bar {
        flex-direction: column;
    }

    .search-input {
        max-width: none;
    }

    .data-table {
        font-size: 0.8125rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.625rem;
    }
}
