/* ── CSS Variables ──────────────────────────────────────────────────────── */
:root {
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-paid: #f59e0b;
    --color-free: #10b981;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--color-bg); color: var(--color-text); line-height: 1.5; min-height: 100vh; }
img { max-width: 100%; }
a { color: var(--color-primary); }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
hr { border: none; border-top: 1px solid var(--color-border); margin: 1.5rem 0; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.header { background: var(--color-surface); border-bottom: 1px solid var(--color-border); padding: 0 1.5rem; height: 60px; display: flex; align-items: center; gap: 1.5rem; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow); }
.header-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--color-text); text-decoration: none; white-space: nowrap; }
.brand-icon { font-size: 1.4rem; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav-link { padding: .5rem .75rem; border-radius: var(--radius); text-decoration: none; color: var(--color-text-muted); font-weight: 500; font-size: .9rem; transition: background .15s, color .15s; }
.nav-link:hover, .nav-link.active { background: #f1f5f9; color: var(--color-primary); }
.header-user { display: flex; align-items: center; gap: .75rem; margin-left: auto; }
.user-email { font-size: .85rem; color: var(--color-text-muted); }

/* ── Main ───────────────────────────────────────────────────────────────── */
.main { max-width: 1200px; margin: 0 auto; padding: 2rem 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; }
.page-header h2 { font-size: 1.2rem; font-weight: 600; }
.subtitle { color: var(--color-text-muted); font-size: .9rem; margin-top: .25rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: .375rem; padding: .5rem 1rem; border-radius: var(--radius); border: none; font-size: .875rem; font-weight: 500; text-decoration: none; transition: background .15s, opacity .15s; white-space: nowrap; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-secondary { background: #f1f5f9; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--color-text-muted); border: 1px solid var(--color-border); }
.btn-ghost:hover:not(:disabled) { background: #f1f5f9; }
.btn-link { background: none; color: var(--color-primary); border: none; padding: 0; font-size: .875rem; text-decoration: underline; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.75rem; font-size: 1rem; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: .125rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.badge-paid { background: #fef3c7; color: #92400e; }
.badge-free { background: #d1fae5; color: #065f46; }
.badge-source { background: #ede9fe; color: #5b21b6; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-deprecated { background: #fee2e2; color: #991b1b; }
.badge-evaluation { background: #dbeafe; color: #1e40af; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-failed { background: #fee2e2; color: #991b1b; }
.badge-running { background: #dbeafe; color: #1e40af; }

/* ── Stats Grid ──────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--color-primary); }
.stat-label { font-size: .875rem; color: var(--color-text-muted); margin-top: .25rem; }

/* ── Category Breakdown ──────────────────────────────────────────────────── */
.category-breakdown { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; }
.category-bar-item { display: grid; grid-template-columns: 120px 1fr 40px; align-items: center; gap: .75rem; padding: .35rem 0; }
.category-name { font-size: .875rem; color: var(--color-text); text-transform: capitalize; }
.category-bar-wrap { background: #f1f5f9; border-radius: 999px; height: 8px; overflow: hidden; }
.category-bar { background: var(--color-primary); height: 100%; border-radius: 999px; min-width: 4px; }
.category-count { font-size: .875rem; color: var(--color-text-muted); text-align: right; }

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filter-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; }
.filter-input { padding: .5rem .75rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: .875rem; background: var(--color-surface); flex: 1; min-width: 180px; }
.filter-select { padding: .5rem .75rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: .875rem; background: var(--color-surface); }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

/* ── Tools Grid ──────────────────────────────────────────────────────────── */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.tool-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; cursor: pointer; transition: box-shadow .15s, transform .15s; display: flex; flex-direction: column; gap: .75rem; }
.tool-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tool-card-header { display: flex; align-items: flex-start; gap: .75rem; }
.tool-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; flex-shrink: 0; }
.tool-icon { font-size: 2rem; flex-shrink: 0; }
.tool-card-title h3 { font-size: 1rem; font-weight: 600; }
.tool-category { font-size: .75rem; color: var(--color-text-muted); text-transform: capitalize; }
.tool-description { font-size: .875rem; color: var(--color-text-muted); flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tool-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.tool-users { font-size: .8rem; color: var(--color-text-muted); }
.tool-badges { display: flex; gap: .25rem; flex-wrap: wrap; }

/* ── Tool Detail ──────────────────────────────────────────────────────────── */
.tool-detail-header { display: flex; gap: 1rem; align-items: center; margin-bottom: 1.25rem; }
.tool-logo-large { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; }
.tool-icon-large { font-size: 3.5rem; }
.tool-detail h2 { font-size: 1.375rem; font-weight: 700; }
.detail-meta { display: flex; gap: .375rem; flex-wrap: wrap; margin-top: .375rem; }
.tool-detail-description { color: var(--color-text-muted); margin-bottom: 1rem; }
.detail-section { margin-top: 1.25rem; }
.detail-section h4 { font-size: .9rem; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .75rem; }
.detail-list { display: grid; grid-template-columns: 140px 1fr; gap: .5rem .75rem; font-size: .875rem; }
.detail-list dt { color: var(--color-text-muted); }
.detail-list dd { font-weight: 500; }
.users-list { display: flex; flex-wrap: wrap; gap: .375rem; max-height: 120px; overflow-y: auto; }
.user-chip { background: #f1f5f9; border-radius: 999px; padding: .2rem .6rem; font-size: .75rem; }
.user-chip.more { background: #e2e8f0; font-style: italic; }
.tag { display: inline-block; background: #ede9fe; color: #5b21b6; border-radius: 4px; padding: .15rem .5rem; font-size: .75rem; margin: .1rem; }
.modal-actions { display: flex; gap: .75rem; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--color-border); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .375rem; }
.form-group label { font-size: .875rem; font-weight: 500; color: var(--color-text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-input { padding: .5rem .75rem; border: 1px solid var(--color-border); border-radius: var(--radius); font-size: .875rem; background: var(--color-surface); width: 100%; }
.form-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
textarea.form-input { resize: vertical; }
.form-actions { display: flex; gap: .75rem; justify-content: flex-end; padding-top: .5rem; }
.hint { font-size: .8rem; color: var(--color-text-muted); margin-bottom: .5rem; }

/* ── Admin ───────────────────────────────────────────────────────────────── */
.admin-section { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem; }
.admin-section h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.sync-actions { display: flex; gap: .75rem; margin-bottom: 1rem; }
.info { color: #1e40af; }
.success { color: var(--color-success); }
.error { color: var(--color-danger); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { text-align: left; padding: .625rem .75rem; border-bottom: 2px solid var(--color-border); font-weight: 600; color: var(--color-text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.data-table td { padding: .625rem .75rem; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; }
.modal-overlay.hidden { display: none; }
.modal-box { background: var(--color-surface); border-radius: var(--radius); width: 100%; max-width: 680px; padding: 2rem; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-close { position: absolute; top: 1rem; right: 1rem; background: none; border: none; font-size: 1.25rem; color: var(--color-text-muted); padding: .25rem .5rem; border-radius: 4px; }
.modal-close:hover { background: #f1f5f9; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast { padding: .75rem 1rem; border-radius: var(--radius); font-size: .875rem; max-width: 320px; opacity: 0; transform: translateY(8px); transition: opacity .25s, transform .25s; pointer-events: none; box-shadow: var(--shadow-md); }
.toast-show { opacity: 1; transform: none; }
.toast-success { background: #dcfce7; color: #166534; border-left: 3px solid var(--color-success); }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 3px solid var(--color-danger); }
.toast-info { background: #dbeafe; color: #1e40af; border-left: 3px solid #3b82f6; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-card { background: var(--color-surface); border-radius: 12px; padding: 3rem 2.5rem; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.2); max-width: 380px; width: 100%; }
.login-logo { font-size: 3.5rem; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .5rem; }
.login-card p { color: var(--color-text-muted); margin-bottom: 2rem; }

/* ── Loader / skeleton ───────────────────────────────────────────────────── */
.loader { width: 32px; height: 32px; border: 3px solid var(--color-border); border-top-color: var(--color-primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 3rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%); background-size: 200%; animation: shimmer 1.4s infinite; border-radius: var(--radius); height: 100px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: 1rem 1.25rem; border-radius: var(--radius); font-size: .875rem; }
.alert-error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--color-danger); }
.empty-state { color: var(--color-text-muted); text-align: center; padding: 3rem 1rem; font-size: 1rem; }

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

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .main { padding: 1rem; }
    .tools-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .modal-box { padding: 1.25rem; }
    .header { padding: 0 1rem; }
    .user-email { display: none; }
    .detail-list { grid-template-columns: 100px 1fr; }
}
