:root {
    --bg: #f7fafa;
    --panel: #ffffff;
    --line: #efefef;
    --line-soft: #f7f7f7;
    --text: #292929;
    --text-soft: #656565;
    --text-muted: #989898;
    --primary: #0ba9aa;
    --primary-soft: #f1f6f7;
    --success: #027a48;
    --danger: #b42318;
    --warning: #b45309;
    --radius: 12px;
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 242px minmax(0, 1fr);
}

.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--line);
    min-height: 100vh;
    position: sticky;
    top: 0;
    align-self: start;
}

.brand {
    height: 80px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line-soft);
}

.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background:
        radial-gradient(circle at 30% 30%, #ffffff 0 2px, transparent 3px),
        linear-gradient(135deg, var(--tenant-color, var(--primary)), #62d6ce);
    box-shadow: 0 8px 18px rgba(11, 169, 170, 0.2);
}

.brand strong {
    font-size: 20px;
    line-height: 1;
    letter-spacing: 0;
}

.nav {
    padding: 16px 20px 28px;
}

.nav-label {
    color: #7c7c7c;
    font-size: 12px;
    line-height: 18px;
    margin: 18px 12px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

.nav-link:hover,
.nav-link.active {
    background: var(--primary-soft);
}

.nav-link svg,
.icon-button svg,
.btn svg {
    width: 16px;
    height: 16px;
}

.main {
    min-width: 0;
}

.topbar {
    height: 80px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 20px 24px;
}

.search-box {
    width: min(440px, 100%);
    height: 40px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    color: var(--text-muted);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.icon-button {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 32px;
    background: #fafafa;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #d2eeeb;
    color: var(--text);
    font-weight: 700;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-meta strong,
.user-meta span {
    display: block;
    white-space: nowrap;
}

.user-meta strong {
    font-size: 14px;
}

.user-meta span {
    color: var(--text-soft);
    font-size: 12px;
    line-height: 18px;
}

.content {
    padding: 24px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-title h1 {
    font-size: 24px;
    line-height: 1.25;
    margin: 0 0 4px;
}

.page-title p {
    color: var(--text-soft);
    margin: 0;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
    background: var(--panel);
    border: 1px solid rgba(0, 0, 0, 0.03);
    border-radius: 20px;
    padding: 24px;
}

.metric {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.metric-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #464646;
    font-weight: 500;
}

.metric-value {
    font-size: 24px;
    line-height: 1;
    font-weight: 700;
}

.metric-note {
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 4px;
}

.metric-note strong {
    color: #02af47;
    font-weight: 500;
}

.table-card {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: 20px;
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--line-soft);
}

.table-header h2 {
    margin: 0;
    font-size: 18px;
}

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

.data-table th {
    background: #fafafa;
    border-bottom: 1px solid #f5f5f5;
    color: #45556c;
    font-size: 12px;
    font-weight: 600;
    line-height: 18px;
    padding: 8px 16px;
    text-align: left;
}

.data-table td {
    border-bottom: 1px solid var(--line-soft);
    color: #45556c;
    height: 64px;
    padding: 12px 16px;
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.muted {
    color: var(--text-soft);
}

.small {
    font-size: 12px;
    line-height: 18px;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 5px;
    padding: 2px 8px;
    font-size: 12px;
    line-height: 18px;
    font-weight: 600;
}

.badge.success {
    background: #ecfdf3;
    color: var(--success);
}

.badge.neutral {
    background: #efefef;
    color: #464646;
}

.badge.info {
    background: #eff8ff;
    color: #1447e6;
}

.badge.danger {
    background: #fef3f2;
    color: var(--danger);
}

.btn-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 9px 14px;
    background: var(--panel);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    cursor: pointer;
}

.btn.primary {
    background: var(--tenant-color, var(--primary));
    border-color: var(--tenant-color, var(--primary));
    color: #ffffff;
}

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

.btn.ghost {
    border-color: transparent;
    background: transparent;
    color: var(--text-soft);
}

.form-card {
    background: var(--panel);
    border: 1px solid rgba(0, 0, 0, 0.03);
    border-radius: 20px;
    padding: 24px;
    max-width: 920px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field.full {
    grid-column: 1 / -1;
}

.field label {
    color: #464646;
    font-weight: 600;
    font-size: 13px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    min-height: 42px;
    padding: 10px 12px;
    background: #ffffff;
    color: var(--text);
}

.field textarea {
    min-height: 150px;
    resize: vertical;
}

.field input[type="color"] {
    padding: 4px;
    min-height: 42px;
}

.help {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 18px;
}

.alert {
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: #ffffff;
}

.alert.success {
    background: #ecfdf3;
    border-color: #abefc6;
    color: #027a48;
}

.alert.error {
    background: #fef3f2;
    border-color: #fecdca;
    color: var(--danger);
}

.key-box,
.code-box {
    background: #111827;
    color: #f9fafb;
    border-radius: 12px;
    padding: 16px;
    overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
    background: var(--bg);
}

.auth-card {
    width: min(560px, 100%);
    background: #ffffff;
    border: 1px solid var(--line-soft);
    border-radius: 20px;
    padding: 28px;
}

.auth-card.wide {
    width: min(920px, 100%);
}

.pagination {
    padding: 16px 20px;
}

.inline-form {
    display: inline;
}

.empty {
    padding: 32px;
    text-align: center;
    color: var(--text-soft);
}

@media (max-width: 1040px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        min-height: auto;
    }

    .nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding: 12px;
    }

    .nav-label {
        display: none;
    }

    .nav-link {
        white-space: nowrap;
    }

    .grid.stats,
    .grid.two,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        height: auto;
        align-items: flex-start;
        flex-direction: column;
    }

    .top-actions {
        width: 100%;
        justify-content: space-between;
    }
}
