/* ===========================================================
   Royex Signal — Design System
   Bright, flat, modern. No gradients, minimal shadows.
   =========================================================== */

:root {
    /* Surfaces */
    --bg-page: #f8f9fb;
    --bg-surface: #ffffff;
    --bg-secondary: #f1f3f6;
    --bg-tertiary: #e9ecef;

    /* Text */
    --text-primary: #1a1d24;
    --text-secondary: #5a6270;
    --text-tertiary: #8a92a1;
    --text-info: #1864ab;
    --text-success: #2b8a3e;
    --text-warning: #b8860b;
    --text-danger: #c92a2a;

    /* Borders */
    --border-tertiary: rgba(0, 0, 0, 0.08);
    --border-secondary: rgba(0, 0, 0, 0.15);
    --border-primary: rgba(0, 0, 0, 0.25);

    /* Accent (Royex brand-ish blue) */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: #eff6ff;
    --accent-text: #1e3a8a;

    /* Status backgrounds */
    --bg-success: #ecfdf5;
    --bg-warning: #fef3c7;
    --bg-danger: #fef2f2;
    --bg-info: #eff6ff;

    /* Layout */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;

    /* Spacing scale */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;
    --sp-7: 48px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
    --font-mono: "SF Mono", Monaco, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3, h4 { font-weight: 500; margin: 0 0 var(--sp-3); line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

p { margin: 0 0 var(--sp-3); }

/* ===== App shell ===== */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.app.no-sidebar { grid-template-columns: 1fr; }

.sidebar {
    background: var(--bg-surface);
    border-right: 0.5px solid var(--border-tertiary);
    padding: var(--sp-5) 0;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 0 var(--sp-5) var(--sp-5);
    border-bottom: 0.5px solid var(--border-tertiary);
    margin-bottom: var(--sp-3);
}
.sidebar-brand .name { font-size: 16px; font-weight: 500; }
.sidebar-brand .tag { font-size: 11px; color: var(--text-tertiary); letter-spacing: 0.1em; text-transform: uppercase; }

.sidebar-section { padding: var(--sp-3) var(--sp-5) var(--sp-1); font-size: 11px; color: var(--text-tertiary);
    letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500; }
.nav-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-5);
    color: var(--text-secondary);
    font-size: 13px;
    border-left: 3px solid transparent;
    text-decoration: none;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); border-left-color: var(--accent); font-weight: 500; }
.nav-item .icon { width: 18px; height: 18px; display: inline-flex; }

.main { padding: var(--sp-5) var(--sp-6); max-width: 1280px; }

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-5);
    border-bottom: 0.5px solid var(--border-tertiary);
}
.topbar-title { display: flex; flex-direction: column; gap: 2px; }
.topbar-title h1 { margin: 0; }
.topbar-title .sub { color: var(--text-secondary); font-size: 13px; }

/* ===== Cards ===== */
.card {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-tertiary);
    border-radius: var(--radius-lg);
    padding: var(--sp-4) var(--sp-5);
    margin-bottom: var(--sp-4);
}
.card-flat { background: transparent; border: none; padding: 0; }
.card-tight { padding: var(--sp-3) var(--sp-4); }
.card-title { font-weight: 500; font-size: 15px; margin-bottom: var(--sp-3); }

/* ===== Metric cards ===== */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.metric {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-tertiary);
    border-radius: var(--radius-md);
    padding: var(--sp-4);
}
.metric-label { font-size: 12px; color: var(--text-secondary); margin: 0 0 6px; }
.metric-value { font-size: 24px; font-weight: 500; margin: 0; line-height: 1.2; }
.metric-delta { font-size: 11px; margin-top: 4px; color: var(--text-tertiary); }
.metric-delta.up { color: var(--text-success); }
.metric-delta.down { color: var(--text-danger); }

/* ===== Forms ===== */
.form-group { margin-bottom: var(--sp-4); }
.form-label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 6px; color: var(--text-primary); }
.form-hint { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.form-error { font-size: 12px; color: var(--text-danger); margin-top: 4px; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=url], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 0.5px solid var(--border-secondary);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color 0.1s ease;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
textarea.code-input { font-family: var(--font-mono); font-size: 12px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 0.5px solid var(--border-secondary);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s ease;
    text-decoration: none;
    font-family: var(--font-sans);
}
.btn:hover { background: var(--bg-secondary); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); color: white; }
.btn-danger { color: var(--text-danger); border-color: rgba(201, 42, 42, 0.3); }
.btn-danger:hover { background: var(--bg-danger); }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { background: var(--bg-secondary); border-color: var(--border-tertiary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; }

.btn-row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

/* ===== Pills / badges ===== */
.pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.pill-success { background: var(--bg-success); color: var(--text-success); }
.pill-warning { background: var(--bg-warning); color: var(--text-warning); }
.pill-danger { background: var(--bg-danger); color: var(--text-danger); }
.pill-info { background: var(--accent-bg); color: var(--accent-text); }
.pill-hot { background: #fef3c7; color: #b8860b; }
.pill-dim { background: transparent; border: 0.5px solid var(--border-tertiary); color: var(--text-tertiary); }

.tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-right: 4px;
}

/* ===== Tables ===== */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 0.5px solid var(--border-tertiary);
}
.table thead { background: var(--bg-secondary); }
.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 0.5px solid var(--border-tertiary);
}
.table td {
    padding: 12px 14px;
    font-size: 13px;
    border-bottom: 0.5px solid var(--border-tertiary);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-secondary); }

/* ===== Avatar / initials ===== */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: 8px;
    font-weight: 500; font-size: 13px;
    flex-shrink: 0;
}
.avatar-lg { width: 56px; height: 56px; font-size: 18px; border-radius: 10px; }
.avatar-sm { width: 30px; height: 30px; font-size: 11px; border-radius: 6px; }
.avatar-round { border-radius: 50%; }

/* Avatar color variations (deterministic from string hash) */
.av-1 { background: #dbeafe; color: #1e40af; }
.av-2 { background: #dcfce7; color: #166534; }
.av-3 { background: #fef3c7; color: #92400e; }
.av-4 { background: #fce7f3; color: #9d174d; }
.av-5 { background: #e0e7ff; color: #3730a3; }
.av-6 { background: #fee2e2; color: #991b1b; }
.av-7 { background: #ccfbf1; color: #115e59; }

/* ===== Lead card (used on search results) ===== */
.lead-card {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-tertiary);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    margin-bottom: var(--sp-3);
    transition: border-color 0.1s ease;
}
.lead-card:hover { border-color: var(--border-secondary); }

/* ===== Status indicators ===== */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-success { background: #22c55e; }
.dot-warning { background: #f59e0b; }
.dot-danger { background: #ef4444; }
.dot-info { background: #3b82f6; }
.dot-muted { background: #94a3b8; }
.dot-pulse { animation: dotpulse 1.5s ease-in-out infinite; }
@keyframes dotpulse { 0%,100% { opacity:1; } 50% { opacity: 0.3; } }

/* ===== Utility ===== */
.row-flex { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.col-flex { display: flex; flex-direction: column; gap: var(--sp-2); }
.flex-gap { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.muted { color: var(--text-secondary); }
.muted-strong { color: var(--text-tertiary); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--sp-1); } .mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); } .mt-5 { margin-top: var(--sp-5); }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: var(--sp-1); } .mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.w-full { width: 100%; }
.fade-in { animation: fadeIn 0.15s ease-out; }
@keyframes fadeIn { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform: translateY(0); } }

/* ===== Flash messages ===== */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-4);
    font-size: 13px;
    border: 0.5px solid var(--border-tertiary);
}
.flash-success { background: var(--bg-success); color: var(--text-success); border-color: rgba(34, 197, 94, 0.3); }
.flash-error { background: var(--bg-danger); color: var(--text-danger); border-color: rgba(239, 68, 68, 0.3); }
.flash-info { background: var(--bg-info); color: var(--accent-text); border-color: rgba(59, 130, 246, 0.3); }

/* ===== Search input (hero) ===== */
.search-hero {
    position: relative;
    margin-bottom: var(--sp-3);
}
.search-hero input {
    padding: 16px 18px 16px 48px;
    font-size: 15px;
    border-radius: var(--radius-lg);
}
.search-hero .icon {
    position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
    color: var(--text-tertiary); font-size: 20px; pointer-events: none;
}

/* ===== Login / minimal pages ===== */
.minimal-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: var(--sp-5);
    background: var(--bg-page);
}
.minimal-card {
    background: var(--bg-surface);
    border: 0.5px solid var(--border-tertiary);
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
    width: 100%;
    max-width: 400px;
}
.minimal-card .brand {
    text-align: center;
    margin-bottom: var(--sp-5);
}
.minimal-card .brand .tag {
    font-size: 11px; color: var(--text-tertiary);
    letter-spacing: 0.1em; text-transform: uppercase;
}
.minimal-card .brand h1 { margin: 4px 0 0; }

/* ===== Score colors ===== */
.score-high { background: #ecfdf5; color: #047857; }
.score-med  { background: #fef3c7; color: #92400e; }
.score-low  { background: #f1f3f6; color: #64748b; }

/* ===== Activity feed ===== */
.feed-row {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 10px 0;
    border-bottom: 0.5px solid var(--border-tertiary);
    font-size: 13px;
}
.feed-row:last-child { border-bottom: none; }
.feed-row .feed-time { color: var(--text-tertiary); font-size: 11px; margin-left: auto; flex-shrink: 0; }
.feed-row .feed-text { flex: 1; min-width: 0; }
.feed-row .feed-text b { font-weight: 500; }

/* ===== Progress bars ===== */
.bar-track { height: 6px; background: var(--bg-secondary); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.bar-fill.success { background: #22c55e; }
.bar-fill.warning { background: #f59e0b; }
.bar-fill.danger { background: #ef4444; }

/* ===== Modal-ish containers ===== */
.section-divider {
    height: 1px;
    background: var(--border-tertiary);
    margin: var(--sp-5) 0;
    border: none;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; top: 0; left: -240px; z-index: 100; transition: left 0.2s; }
    .sidebar.open { left: 0; }
    .main { padding: var(--sp-4); }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
}
