/**
 * CCM API Hub - Stylesheet
 * Dark theme with ClickClickMedia brand green.
 * Based on WebWatch design language.
 * 
 * @version 1.0.0
 */

/* ─── CSS Custom Properties ─────────────────────────────────── */
:root {
    /* Brand Colors */
    --brand-primary: #94c83e;
    --brand-secondary: #7ab32a;

    /* Background Colors */
    --bg-primary: #101010;
    --bg-secondary: #0a0a0a;
    --bg-card: #141414;
    --bg-hover: #1a1a1a;
    --bg-input: #1a1a1a;

    /* Text Colors */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0a0a0a;

    /* Accent Colors */
    --accent-primary: #94c83e;
    --accent-success: #22c55e;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-info: #3b82f6;

    /* Border Colors */
    --border-color: #1e3a5f;
    --border-light: #2d2d2d;

    /* Status Colors */
    --status-online: #22c55e;
    --status-offline: #ef4444;
    --status-warning: #f59e0b;
    --status-unknown: #64748b;

    /* Border Radius */
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 12px;
    --border-radius-xl: 16px;
    --border-radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);

    /* Font */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-secondary);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--brand-secondary);
}

code {
    background: var(--bg-hover);
    padding: 0.15em 0.4em;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-mono);
    font-size: 0.85em;
}

/* ─── App Header ────────────────────────────────────────────── */
.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.app-logo-icon {
    color: var(--brand-primary);
    font-size: 1.3rem;
}

.header-nav {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.4rem 0.85rem;
    border-radius: var(--border-radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-link.active {
    color: var(--brand-primary);
    background: rgba(148, 200, 62, 0.08);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.version-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 0.2rem 0.5rem;
    border-radius: var(--border-radius-full);
    font-family: var(--font-mono);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
}

.user-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* ─── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: var(--border-radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-admin {
    background: rgba(148, 200, 62, 0.15);
    color: var(--brand-primary);
}

.badge-manager {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-info);
}

.badge-viewer {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-secondary);
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-success);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-warning);
}

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-info);
}

/* ─── Layout ────────────────────────────────────────────────── */
.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

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

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0.25rem 0 0;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2, .card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ─── Stats Grid ────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 1.25rem;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-card .stat-change {
    font-size: 0.75rem;
    margin-top: 0.4rem;
}

.stat-change.positive { color: var(--accent-success); }
.stat-change.negative { color: var(--accent-danger); }
.stat-change.neutral  { color: var(--text-muted); }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-normal);
    text-decoration: none;
    line-height: 1.4;
    font-family: var(--font-family);
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

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

.btn-primary:hover {
    background: var(--brand-secondary);
    color: var(--text-inverse);
}

.btn-success {
    background: var(--accent-success);
    color: #fff;
}

.btn-danger {
    background: var(--accent-danger);
    color: #fff;
}

.btn-outline {
    background: transparent;
    border-color: var(--border-light);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.3rem 0.5rem;
}

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

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

/* ─── Tables ────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
}

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

thead th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

tbody td {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

tbody tr:hover {
    background: var(--bg-hover);
}

tbody tr:last-child td {
    border-bottom: none;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

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

.form-input,
input[type="text"],
input[type="url"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--border-radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-family);
    transition: border-color var(--transition-fast);
    box-sizing: border-box;
}

.form-input:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px rgba(148, 200, 62, 0.15);
}

select {
    appearance: auto;
    cursor: pointer;
}

textarea {
    font-family: var(--font-mono);
    resize: vertical;
    min-height: 80px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

/* ─── Alerts ────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--accent-success);
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--accent-danger);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--accent-warning);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: var(--accent-info);
}

/* ─── Modals ────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

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

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-xl);
    max-width: 540px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ─── Toast Notifications ───────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 70px;
    right: 1rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--border-radius-md);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 380px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast-success { background: #166534; color: #bbf7d0; }
.toast-error   { background: #991b1b; color: #fecaca; }
.toast-warning { background: #92400e; color: #fde68a; }
.toast-info    { background: #1e3a5f; color: #bfdbfe; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ─── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
}

.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto 1.5rem;
}

/* ─── Score Circles (PageSpeed) ─────────────────────────────── */
.score-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
}

.score-good     { background: rgba(34, 197, 94, 0.15); color: var(--accent-success); border: 2px solid var(--accent-success); }
.score-average  { background: rgba(245, 158, 11, 0.15); color: var(--accent-warning); border: 2px solid var(--accent-warning); }
.score-poor     { background: rgba(239, 68, 68, 0.15); color: var(--accent-danger); border: 2px solid var(--accent-danger); }

/* ─── Spinner ───────────────────────────────────────────────── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-light);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Utilities ─────────────────────────────────────────────── */
.text-success { color: var(--accent-success); }
.text-danger  { color: var(--accent-danger); }
.text-warning { color: var(--accent-warning); }
.text-info    { color: var(--accent-info); }
.text-muted   { color: var(--text-muted); }
.text-brand   { color: var(--brand-primary); }

.text-right  { text-align: right; }
.text-center { text-align: center; }

.mt-0  { margin-top: 0; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mb-0  { margin-bottom: 0; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }

.flex       { display: flex; }
.items-center { align-items: center; }
.gap-1      { gap: 0.5rem; }
.gap-2      { gap: 1rem; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .header-nav { display: none; }
}

@media (max-width: 600px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-container { padding: 1rem; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}
