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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3345;
    --text: #e1e4ed;
    --text-dim: #8b8fa3;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 8px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.2rem;
    font-weight: 700;
    margin-right: 2rem;
}

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

.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    transition: all 0.2s;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--primary); background: rgba(99,102,241,0.1); }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
}

h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 0.75rem; }

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

/* Status Bar */
.status {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
.status-ok { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }
.status-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: var(--danger); }
.error-text { color: var(--danger); }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
.data-table thead { background: var(--surface2); }
.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
}
.data-table td {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}
.data-table tbody tr:hover { background: var(--surface2); }

.title-cell { max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.price { font-weight: 600; color: var(--success); white-space: nowrap; }

.table-info {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.link-btn {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
}
.link-btn:hover { color: var(--primary-hover); text-decoration: underline; }

/* Forms */
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font);
}
.form-control:focus { outline: none; border-color: var(--primary); }

.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--text-dim); }
.form-group-wide { flex: 2; }
.form-group-btn { justify-content: flex-end; }

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.form-row .form-group { flex: 1; min-width: 150px; }

.settings-form, .add-rule-form {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-inactive { background: rgba(245,158,11,0.15); color: var(--warning); }

/* Alerts */
.alert {
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: var(--success); }

/* Misc */
.actions { display: flex; gap: 0.4rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.help-text { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 1rem; }
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-dim);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}
.loading { text-align: center; padding: 2rem; color: var(--text-dim); }

.spinner {
    display: none;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.htmx-request .spinner, .htmx-request.spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.match-row { background: rgba(99,102,241,0.05); }

/* Table toolbar & search */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    gap: 1rem;
}
.table-search {
    max-width: 300px;
}

/* Sort indicators */
th[data-sort] { cursor: pointer; user-select: none; position: relative; padding-right: 1.5rem !important; }
th[data-sort]::after { content: "⇅"; position: absolute; right: 0.4rem; opacity: 0.3; font-size: 0.75rem; }
th.sort-asc::after { content: "▲"; opacity: 0.8; }
th.sort-desc::after { content: "▼"; opacity: 0.8; }
th[data-sort]:hover { color: var(--text); background: rgba(99,102,241,0.08); }
