:root {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #3b82f6;
    --radius: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

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

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 18px;
    color: #fff;
}

.sidebar-nav {
    padding: 12px 0;
}

.nav-item {
    display: block;
    padding: 10px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
}

.main-content {
    margin-left: 240px;
    flex: 1;
    min-height: 100vh;
}

.topbar {
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 24px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.content {
    padding: 24px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s;
}

.stat-card:hover {
    border-color: var(--primary);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    background: var(--bg-card);
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s;
}

.btn:hover {
    background: var(--bg);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

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

/* .btn:hover sets a light background, which would leave the white text unreadable */
.btn-danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* Auth Pages — split layout with gradient */
.auth-container {
    display: flex;
    min-height: 100vh;
}

.auth-left {
    width: 50%;
    position: relative;
    overflow: hidden;
}

.auth-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #a8edea 0%, #99c4f7 25%, #c2a0f5 50%, #f0abfc 75%, #a8edea 100%);
    background-size: 300% 300%;
    animation: gradientShift 12s ease infinite;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.auth-right {
    width: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
}

.auth-form-wrapper {
    width: 100%;
    max-width: 380px;
    padding: 0 24px;
}

.auth-logo {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: 8px;
    margin-bottom: 40px;
    text-align: center;
}

.logo-p, .logo-t, .logo-r, .logo-a, .logo-n { color: #1a1a1a; }
.logo-e { color: #e11d48; }

.auth-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 6px;
}

.auth-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.auth-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.forgot-link {
    font-size: 14px;
    color: var(--primary);
    text-decoration: none;
}

.forgot-link:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .auth-container { flex-direction: column; }
    .auth-left { width: 100%; height: 200px; }
    .auth-right { width: 100%; }
    .auth-form-wrapper { padding: 32px 24px; }
}

/* Alerts */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: var(--success);
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}

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

th, td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    background: var(--bg);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tr:hover td {
    background: rgba(0,0,0,0.01);
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h1 {
    font-size: 22px;
}

/* Form card */
.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 600px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Form row (two-column layout) */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; }
}

/* Badge */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted { background: #f3f4f6; color: #6b7280; }

/* Actions cell */
.actions-cell {
    display: flex;
    gap: 8px;
}

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 400px;
}

.toast-visible {
    transform: translateX(0);
    opacity: 1;
}

.toast-success {
    background: #065f46;
    color: #fff;
    border-left: 4px solid #34d399;
}

.toast-error {
    background: #991b1b;
    color: #fff;
    border-left: 4px solid #f87171;
}

.toast-msg { flex: 1; }

.toast-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    padding: 0 2px;
}

.toast-close:hover { opacity: 1; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-box {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-box h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-box p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin: 24px 0 12px;
}

.feature-tree {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.feature-tree .feature-tree {
    padding-left: 22px;
}

.feature-tree label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-weight: normal;
    cursor: pointer;
}

.tenant-form .form-card + .form-card,
.tenant-form > .form-actions {
    margin-top: 16px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-weight: normal;
    cursor: pointer;
}

.check-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
}

.channel-group {
    margin-bottom: 20px;
}

.channel-group-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.channel-group table input,
.channel-group table select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text);
}

.channel-group table td {
    padding: 4px 8px 4px 0;
}

.channel-group table td:first-child {
    width: 40%;
}

.channel-group table select {
    min-width: 96px;
}

.channel-group .channel-add {
    margin-top: 6px;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 8px 14px;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.pager {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 13px;
}

.filter-bar select, .filter-bar input {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.log-line {
    font-size: 12px;
    color: var(--text-muted);
    word-break: break-all;
}

.log-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.method { font-weight: 600; }
.method-GET { color: #2563eb; }
.method-POST { color: #16a34a; }
.method-PUT, .method-PATCH { color: #d97706; }
.method-DELETE { color: #dc2626; }

.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }

.modal-wide {
    max-width: 800px;
    width: 90%;
}

.view-text {
    max-height: 60vh;
    overflow: auto;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.import-form {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.import-form input[type="file"] {
    font-size: 13px;
    max-width: 220px;
}

.import-problems {
    border-color: #fca5a5;
    background: #fef2f2;
    margin-bottom: 16px;
}

.import-problems ul {
    margin: 8px 0 0 18px;
}

.perm-depth-0 { font-weight: 600; }
.perm-depth-1 { padding-left: 20px; }
.perm-depth-2 { padding-left: 40px; }
.perm-depth-3 { padding-left: 60px; }

.row-warning td { background: #fffbeb; }
.registry-warning { color: #92400e; font-size: 12px; margin-top: 2px; }

.check-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.check-form input[type="text"] {
    min-width: 260px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.check-answer {
    width: 100%;
    font-size: 13px;
}

.code-tree {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.code-tree .code-tree {
    padding-left: 22px;
}

/* SVG icons of parameters (shown through <img>, see svgDataURI) */
.svg-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    vertical-align: middle;
}

.svg-field {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.svg-field textarea {
    flex: 1;
}

.svg-preview {
    flex: 0 0 96px;
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f8fafc;
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
}

.svg-preview img {
    max-width: 72px;
    max-height: 72px;
}

/* Search box above a table (data-table-search) and in filter bars */
.table-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.table-search {
    width: 100%;
    max-width: 320px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text);
}

.table-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.filter-bar .table-search {
    padding: 4px 8px;
    font-size: 13px;
    max-width: 260px;
}

tr.search-empty td {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

/* Scrolling body of a modal that shows a table */
.modal-scroll {
    max-height: 60vh;
    overflow: auto;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
