/* ── RCA MW Console — Admin Stylesheet ────────────────────────── */

:root {
    --bg: #f8f7f4;
    --bg-card: #ffffff;
    --bg-hover: #f3f2ee;
    --bg-input: #fafaf8;
    --border: #e8e6e1;
    --border-light: #f0eee8;
    --text: #1a1a1a;
    --text-muted: #888;
    --text-hint: #bbb;
    --accent: #e65100;
    --accent-light: #fff3e0;
    --radius: 10px;
    --radius-lg: 14px;
    --font: 'DM Sans', system-ui, -apple-system, sans-serif;
    /* Badge colors */
    --badge-admin-bg: #fef2f2; --badge-admin-fg: #b91c1c;
    --badge-operator-bg: #eff6ff; --badge-operator-fg: #1d4ed8;
    --badge-fae-bg: #fdf4ff; --badge-fae-fg: #7c3aed;
    --badge-viewer-bg: #f3f2ee; --badge-viewer-fg: #555;
    --badge-active-bg: #ecfdf5; --badge-active-fg: #047857;
    --badge-inactive-bg: #f3f2ee; --badge-inactive-fg: #888;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ──────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: 230px; background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0;
    z-index: 10;
}
.sidebar-brand {
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; gap: 10px;
}
.brand-icon {
    width: 38px; height: 34px; border-radius: 8px;
    background: linear-gradient(135deg, #e65100, #ff8a00);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 12px;
    flex-shrink: 0; letter-spacing: 0.5px;
}
.brand-title { font-weight: 600; font-size: 14px; letter-spacing: -0.3px; }
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.3px; }

.sidebar-nav { flex: 1; padding: 8px; overflow-y: auto; }
.nav-group {
    font-size: 10px; font-weight: 600; color: var(--text-hint);
    text-transform: uppercase; letter-spacing: 1px;
    padding: 8px 10px 4px; margin-top: 4px;
}
.nav-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px; border-radius: 8px;
    font-size: 13px; color: var(--text-muted);
    text-decoration: none; cursor: pointer;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); font-weight: 500; }
.nav-item.disabled { opacity: 0.35; pointer-events: none; }
.nav-item svg { flex-shrink: 0; opacity: 0.5; }
.nav-item.active svg { opacity: 0.8; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border-light); }
.user-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 8px; cursor: pointer;
    transition: background 0.15s;
}
.user-badge:hover { background: var(--bg-hover); }
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ── Main ────────────────────────────────────────────────────── */
.main { flex: 1; margin-left: 230px; padding: 0; min-height: 100vh; }

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
    padding: 20px 28px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card);
}
.page-header h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.3px; }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 1px; }

/* ── Metrics ─────────────────────────────────────────────────── */
.metric-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px; padding: 24px 28px;
}
.metric-card {
    background: var(--bg-card); border-radius: var(--radius);
    border: 1px solid var(--border); padding: 16px;
}
.metric-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.metric-value { font-size: 24px; font-weight: 600; letter-spacing: -0.5px; }

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 16px 28px 0; }

/* ── Table ────────────────────────────────────────────────────── */
.table-wrap {
    margin: 12px 28px 0; border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    background: var(--bg-card);
}
table { width: 100%; border-collapse: collapse; }
thead tr { background: var(--bg); }
th {
    text-align: left; padding: 8px 14px; font-size: 12px;
    font-weight: 500; color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
td { padding: 10px 14px; border-top: 1px solid var(--border-light); font-size: 13px; }
tbody tr:hover { background: var(--bg-hover); }
code { font-family: 'SF Mono', Consolas, monospace; font-size: 12px; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.table-footer { padding: 10px 28px; font-size: 12px; color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
    padding: 7px 16px; border: none; border-radius: 8px;
    background: var(--text); color: white; font-size: 13px;
    font-weight: 500; font-family: var(--font); cursor: pointer;
    transition: all 0.15s; white-space: nowrap;
}
.btn-primary:hover { background: #333; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
    padding: 7px 16px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-card); color: var(--text); font-size: 13px;
    font-weight: 500; font-family: var(--font); cursor: pointer;
    transition: all 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover); }
.btn-icon {
    width: 30px; height: 30px; display: flex; align-items: center;
    justify-content: center; border: 1px solid transparent;
    border-radius: 6px; background: transparent; cursor: pointer;
    color: var(--text-muted); transition: all 0.15s;
    font-size: 18px; line-height: 1;
}
.btn-icon:hover { background: var(--bg-hover); border-color: var(--border); color: var(--text); }

/* ── Inputs ──────────────────────────────────────────────────── */
input[type="text"], input[type="password"], input[type="email"], select, textarea {
    width: 100%; padding: 8px 12px; border-radius: 8px;
    border: 1px solid var(--border); font-size: 13px;
    font-family: var(--font); background: var(--bg-input);
    outline: none; transition: all 0.15s;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent); background: var(--bg-card);
    box-shadow: 0 0 0 3px rgba(230,81,0,0.06);
}
textarea { resize: vertical; min-height: 60px; }
.input-sm { height: 34px; font-size: 13px; }
select.input-sm { padding: 4px 8px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; color: var(--text); }
.checkbox-label input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 10px;
    font-size: 11px; font-weight: 500; white-space: nowrap;
}
.badge-admin { background: var(--badge-admin-bg); color: var(--badge-admin-fg); }
.badge-operator { background: var(--badge-operator-bg); color: var(--badge-operator-fg); }
.badge-fae { background: var(--badge-fae-bg); color: var(--badge-fae-fg); }
.badge-viewer { background: var(--badge-viewer-bg); color: var(--badge-viewer-fg); }
.badge-active { background: var(--badge-active-bg); color: var(--badge-active-fg); }
.badge-inactive { background: var(--badge-inactive-bg); color: var(--badge-inactive-fg); }
.badge-info { background: #e3f2fd; color: #1565c0; }
.badge-location { background: #fce4ec; color: #c62828; }
.badge-area { background: #e8f5e9; color: #2e7d32; }
.badge-department { background: #fff3e0; color: #e65100; }

/* ── Avatars ─────────────────────────────────────────────────── */
.avatar-sm {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600; color: #555;
    flex-shrink: 0; background: #eeedfe;
}
.avatar-sq {
    width: 34px; height: 34px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600; color: #555;
    flex-shrink: 0;
}

/* ── Connection cards ────────────────────────────────────────── */
.conn-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px; padding: 16px 28px;
}
.conn-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 14px 16px;
    transition: border-color 0.15s;
}
.conn-card:hover { border-color: #ccc; }
.conn-card.conn-blocked { border-color: #f5c87a; border-width: 1.5px; }
.conn-card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 8px; }
.conn-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-type { font-size: 11px; color: var(--text-hint); }
.conn-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-footer { display: flex; justify-content: space-between; align-items: center; }
.conn-secret { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }

/* ── Pills ────────────────────────────────────────────────────── */
.pill {
    padding: 5px 14px; border-radius: 20px;
    font-size: 12px; font-family: var(--font);
    border: 1px solid var(--border);
    background: var(--bg-card); color: var(--text-muted);
    cursor: pointer; transition: all 0.15s;
}
.pill:hover { border-color: #ccc; }
.pill.active { background: var(--text); color: white; border-color: var(--text); }

/* ── Info bar ────────────────────────────────────────────────── */
.info-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 16px; margin: 12px 28px;
    background: var(--bg); border-radius: var(--radius);
    font-size: 12px; color: var(--text-muted);
    border: 1px solid var(--border-light);
}

/* ── Modals ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.3);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; backdrop-filter: blur(2px);
}
.modal {
    background: var(--bg-card); border-radius: 16px;
    width: 100%; max-width: 440px; max-height: 90vh;
    overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-lg { max-width: 560px; }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px 20px; }
.modal-footer {
    padding: 12px 20px 16px;
    display: flex; justify-content: flex-end; gap: 8px;
    border-top: 1px solid var(--border-light);
}

/* ── Error ────────────────────────────────────────────────────── */
.error-msg {
    background: #fef2f2; color: #b91c1c; font-size: 13px;
    padding: 8px 12px; border-radius: 8px;
    border: 1px solid #fecaca; margin-top: 4px;
}

/* ── Utility ─────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-danger { color: #b91c1c; }
.fw-500 { font-weight: 500; }
.color-dot {
    display: inline-block; width: 10px; height: 10px;
    border-radius: 50%; vertical-align: middle; margin-right: 2px;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-brand > div:last-child, .nav-item span, .nav-group,
    .user-name, .user-role, .brand-title, .brand-sub { display: none; }
    .nav-item { justify-content: center; padding: 10px; }
    .main { margin-left: 60px; }
    .page-header, .toolbar, .table-wrap, .conn-grid, .info-bar, .table-footer, .metric-grid { padding-left: 16px; padding-right: 16px; }
    .form-row { grid-template-columns: 1fr; }
}

/* ── Action cards (D365 page) ─────────────────────────────────── */
.action-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 16px;
}
.action-card-header { display: flex; align-items: center; gap: 12px; }
.action-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.action-title { font-size: 14px; font-weight: 600; }
.action-desc { font-size: 12px; color: var(--text-muted); }
.action-result {
    margin-top: 8px; padding: 8px 12px; border-radius: 8px;
    font-size: 12px; font-weight: 500;
}
.result-ok { background: #ecfdf5; color: #047857; }
.result-err { background: #fef2f2; color: #b91c1c; }

/* ── Toast notifications ─────────────────────────────────────── */
.toast {
    padding: 10px 16px; border-radius: 10px;
    font-size: 13px; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    animation: toast-in 0.3s ease;
    min-width: 240px; max-width: 400px;
}
.toast-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.toast-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.toast-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.toast-exit { animation: toast-out 0.3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(40px); } }

/* ── RPA Console ─────────────────────────────────────────────── */
.rpa-form-card {
    margin: 12px 28px 0; padding: 18px 20px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.rpa-result-card {
    margin: 12px 28px 0; padding: 14px 18px;
    border-radius: var(--radius-lg); border: 1.5px solid;
}
.rpa-result-ok { background: #f8fdf9; border-color: #a7f3d0; }
.rpa-result-err { background: #fefbfb; border-color: #fecaca; }
.rpa-result-header { display: flex; align-items: center; margin-bottom: 8px; }

/* Steps timeline */
.rpa-steps { display: flex; flex-wrap: wrap; gap: 2px 0; }
.rpa-step {
    display: flex; align-items: center; gap: 6px;
    padding: 3px 10px 3px 0; font-size: 12px;
}
.rpa-step::after {
    content: '→'; color: var(--text-hint); font-size: 11px; margin-left: 4px;
}
.rpa-step:last-child::after { content: ''; }
.rpa-step-dot {
    width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.dot-ok { background: #34d399; }
.dot-warn { background: #fbbf24; }
.dot-err { background: #f87171; }

/* Log detail panel */
.rpa-log-detail {
    margin: 8px 28px 0; padding: 14px 18px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.rpa-pre {
    background: var(--bg); border: 1px solid var(--border-light);
    border-radius: 8px; padding: 10px 12px; margin-top: 4px;
    font-family: 'SF Mono', Consolas, monospace; font-size: 11px;
    white-space: pre-wrap; word-break: break-all;
    max-height: 200px; overflow-y: auto; line-height: 1.5;
}

/* ══════════════════════════════════════════════════════════════ */
/* PHASE 3 STYLES                                                */
/* ══════════════════════════════════════════════════════════════ */

/* ── Generic btn/input/card ──────────────────────────────────── */
.btn {
    padding: 7px 16px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-card); color: var(--text); font-size: 13px;
    font-weight: 500; font-family: var(--font); cursor: pointer;
    transition: all 0.15s; white-space: nowrap; display: inline-flex;
    align-items: center; gap: 6px;
}
.btn:hover { background: var(--bg-hover); border-color: #ccc; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-xs { padding: 2px 8px; font-size: 11px; border-radius: 5px; }
.btn-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.input {
    padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border);
    font-size: 13px; font-family: var(--font); background: var(--bg-input);
    outline: none; color: var(--text);
}
.input:focus { border-color: var(--accent); background: var(--bg-card); box-shadow: 0 0 0 3px rgba(230,81,0,0.06); }
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 20px;
    margin: 12px 28px 0;
}
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.code-sm { font-family: 'SF Mono', Consolas, monospace; font-size: 11px; background: var(--bg); padding: 1px 5px; border-radius: 3px; }

/* ── Status badges (task statuses) ────────────────────────────── */
.status-badge {
    display: inline-block; padding: 2px 8px; border-radius: 10px;
    font-size: 11px; font-weight: 500; white-space: nowrap;
    letter-spacing: 0.02em;
}
.st-created { background: #fef3c7; color: #92400e; }
.st-dispatched-to-rcs, .st-dispatched { background: #fef3c7; color: #92400e; }
.st-executing { background: #dbeafe; color: #1d4ed8; }
.st-in-progress { background: #dbeafe; color: #1d4ed8; }
.st-carrying { background: #dbeafe; color: #1d4ed8; }
.st-completed { background: #d1fae5; color: #065f46; }
.st-cancelled { background: #f3f4f6; color: #6b7280; }
.st-dispatch-failed, .st-failed { background: #fef2f2; color: #b91c1c; }
.st-idle { background: #f3f4f6; color: #6b7280; }
.st-charging { background: #fef3c7; color: #92400e; }

/* ── Tags ─────────────────────────────────────────────────────── */
.tag {
    display: inline-block; padding: 1px 7px; border-radius: 4px;
    font-size: 11px; font-weight: 500; background: var(--bg);
    color: var(--text-muted); border: 1px solid var(--border-light);
}

/* ── Status dots (Active/Inactive indicator) ─────────────────── */
.status-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    cursor: pointer; transition: all 0.2s; vertical-align: middle;
}
.dot-on { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.15); }
.dot-off { background: #d0d0d0; }
.status-dot:hover { transform: scale(1.3); }

/* ── Tabs ─────────────────────────────────────────────────────── */
.tab-bar { padding: 0 28px; }
.tab-btn {
    padding: 6px 14px; border: none; background: transparent;
    font-size: 13px; font-family: var(--font); color: var(--text-muted);
    cursor: pointer; border-radius: 6px 6px 0 0; transition: all 0.15s;
    border-bottom: 2px solid transparent;
}
.tab-btn:hover { color: var(--text); background: var(--bg-hover); }
.tab-btn.tab-active {
    color: var(--accent); font-weight: 500;
    border-bottom-color: var(--accent); background: var(--bg-card);
}

/* ── JSON viewer ──────────────────────────────────────────────── */
.json-view {
    background: var(--bg); border: 1px solid var(--border-light);
    border-radius: 8px; padding: 12px 14px;
    font-family: 'SF Mono', Consolas, monospace; font-size: 11px;
    white-space: pre-wrap; word-break: break-all;
    max-height: 300px; overflow-y: auto; line-height: 1.6;
    color: var(--text);
}

/* ── Timeline (task lifecycle) ────────────────────────────────── */
.timeline { padding: 0; }
.timeline-item {
    display: flex; gap: 10px; padding: 6px 0;
    position: relative;
}
.timeline-item:not(:last-child)::before {
    content: ''; position: absolute;
    left: 5px; top: 22px; bottom: -6px;
    width: 1px; background: var(--border);
}
.timeline-dot {
    width: 11px; height: 11px; border-radius: 50%;
    flex-shrink: 0; margin-top: 4px;
    border: 2px solid var(--bg-card);
}
.dot-info { background: #60a5fa; }
.dot-error { background: #f87171; }
.timeline-content { flex: 1; min-width: 0; }

/* ── Row active highlight ─────────────────────────────────────── */
.row-active { background: var(--accent-light) !important; }

/* ── Color vars for success/danger/warning backgrounds ────────── */
:root {
    --success: #047857;
    --success-bg: #ecfdf5;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --warning: #92400e;
    --warning-bg: #fef3c7;
    --surface: var(--bg-card);
}

/* ── Phase 3 page padding (sub-sections) ──────────────────────── */
div[x-show*="tasks"] .table-wrap,
div[x-show*="rcs-console"] .table-wrap,
div[x-show*="master-data"] .table-wrap {
    margin: 0; border-radius: var(--radius);
}
div[x-show*="tasks"] .metric-grid,
div[x-show*="rcs-console"],
div[x-show*="master-data"] {
    padding: 16px 28px;
}
div[x-show*="tasks"] { padding-bottom: 28px; }

/* ── RCS Console card overrides ──────────────────────────────── */
div[x-show*="rcs-console"] .card {
    margin: 0; max-width: 520px;
}

/* ── Master data table scrolling ─────────────────────────────── */
div[x-show*="master-data"] .table-wrap table thead {
    position: sticky; top: 0; z-index: 1; background: var(--bg);
}


/* ── Settings page (reuses conn-grid/conn-card from Connections) ─ */
.stg-summary {
    display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px;
}
.stg-chip-on, .stg-chip-off {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: 10px; padding: 2px 8px; border-radius: 4px;
}
.stg-chip-on { background: #ecfdf5; color: #047857; }
.stg-chip-off { background: #f3f4f6; color: #6b7280; }
.stg-chip-on b, .stg-chip-off b { font-weight: 600; }

/* Help text in edit modal */
.stg-help {
    font-size: 11px; line-height: 1.5; color: #6b7280;
    margin-top: 4px; padding: 6px 10px;
    background: #f9fafb; border-radius: 6px; border-left: 2px solid #d1d5db;
}
.stg-help code { font-size: 10px; background: #e5e7eb; padding: 1px 4px; border-radius: 3px; }