:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f7fafc;
    --border: #d9e2ec;
    --text: #162033;
    --muted: #66758a;
    --accent: #1f6c5a;
    --accent-strong: #165244;
    --danger: #b54848;
    --shadow: 0 18px 55px rgba(19, 35, 61, 0.08);
    --radius: 20px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top right, rgba(68, 160, 141, 0.16), transparent 30%),
        linear-gradient(180deg, #eef4f8 0%, var(--bg) 55%, #eef3f7 100%);
}

body {
    min-height: 100vh;
}

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

button,
input,
select {
    font: inherit;
}

.eyebrow {
    display: inline-block;
    margin-bottom: 0.6rem;
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.button-primary,
.button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid transparent;
    padding: 0.9rem 1.2rem;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.button-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #fff;
    box-shadow: 0 14px 28px rgba(31, 108, 90, 0.24);
}

.button-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.button-primary:hover,
.button-secondary:hover,
.range-switch__button:hover {
    transform: translateY(-1px);
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: min(1100px, 100%);
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 28px;
    align-items: stretch;
}

.login-brand,
.login-card,
.sidebar,
.dashboard-header,
.widget-card,
.empty-state,
.error-box {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(217, 226, 236, 0.75);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.login-brand,
.login-card {
    padding: 36px;
}

.login-brand h1,
.login-card h2,
.dashboard-header h2,
.empty-state h3 {
    margin: 0 0 0.8rem;
}

.login-brand p,
.login-card p,
.widget-card__header p,
.dashboard-header p,
.empty-state p {
    color: var(--muted);
    line-height: 1.6;
}

.login-brand__cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 32px;
}

.mini-card {
    padding: 18px;
    border-radius: 18px;
    background: linear-gradient(180deg, #f8fbfd 0%, #eef5f8 100%);
    border: 1px solid #dbe7ef;
    display: grid;
    gap: 6px;
}

.mini-card strong {
    font-size: 1rem;
}

.mini-card span {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.stack-form {
    display: grid;
    gap: 18px;
    margin-top: 24px;
}

.form-field {
    display: grid;
    gap: 8px;
}

.form-field span {
    font-weight: 600;
}

.form-field input,
.tenant-switch select {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 14px;
    padding: 0.9rem 1rem;
    color: var(--text);
}

.alert {
    border-radius: 14px;
    padding: 14px 16px;
    margin-top: 20px;
}

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

.alert-success {
    background: #ebf7ef;
    color: var(--accent-strong);
    border: 1px solid #cfe7d6;
}

.dashboard-page {
    padding: 22px;
}

.app-shell {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    min-height: calc(100vh - 44px);
}

.sidebar {
    padding: 24px;
    display: grid;
    gap: 28px;
    align-content: start;
}

.sidebar__brand h1 {
    margin: 0;
    font-size: 1.35rem;
}

.sidebar__label {
    display: inline-block;
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sidebar__tenant-name {
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.sidebar__nav {
    display: grid;
    gap: 10px;
}

.nav-link {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid transparent;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.nav-link small {
    color: var(--muted);
    line-height: 1.45;
}

.nav-link.is-active {
    background: linear-gradient(135deg, rgba(31, 108, 90, 0.12) 0%, rgba(31, 108, 90, 0.06) 100%);
    border-color: rgba(31, 108, 90, 0.22);
}

.nav-link:hover {
    background: rgba(247, 250, 252, 0.95);
    border-color: var(--border);
}

.dashboard-content {
    display: grid;
    gap: 22px;
    align-content: start;
}

.dashboard-header {
    padding: 28px 30px;
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
}

.dashboard-header__meta {
    display: flex;
    justify-content: flex-end;
}

.meta-pill {
    display: grid;
    gap: 4px;
    padding: 14px 18px;
    border-radius: 18px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.meta-pill span {
    color: var(--muted);
    font-size: 0.92rem;
}

.widget-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}

.widget-card {
    min-height: var(--min-height, 220px);
    padding: 22px;
    display: grid;
    gap: 16px;
    transition: box-shadow 0.18s ease, opacity 0.18s ease;
}

.widget-card.span-2 {
    grid-column: span 2;
}

.widget-card.span-3 {
    grid-column: span 3;
}

.widget-card__header {
    display: flex;
    gap: 18px;
    justify-content: space-between;
    align-items: flex-start;
}

.widget-card__header h3 {
    margin: 0 0 6px;
    font-size: 1.1rem;
}

.widget-card__header p {
    margin: 0;
}

.widget-card__body {
    display: grid;
    gap: 14px;
    align-content: start;
    min-height: 0;
}

.widget-status {
    color: var(--muted);
    font-size: 0.95rem;
}

.widget-card.is-loading {
    opacity: 0.92;
}

.widget-render {
    display: grid;
    gap: 16px;
    min-height: 72px;
}

.widget-chart-frame {
    position: relative;
    width: 100%;
    height: var(--chart-height, 280px);
    min-height: 220px;
    max-height: 360px;
}

.widget-canvas {
    display: block;
    width: 100% !important;
    max-width: 100%;
    height: 100% !important;
    min-height: 0;
    max-height: none;
}

.range-switch {
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;
}

.range-switch__button {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.range-switch__button.is-active {
    background: rgba(31, 108, 90, 0.12);
    color: var(--accent-strong);
    border-color: rgba(31, 108, 90, 0.24);
}

.stat-kpi {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.stat-kpi__value {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 700;
    line-height: 1;
}

.stat-kpi__unit {
    color: var(--muted);
    font-size: 1.05rem;
}

.stat-meta,
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.stat-meta__item,
.summary-item {
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    padding: 12px 14px;
    display: grid;
    gap: 4px;
}

.stat-meta__item span,
.summary-item span {
    color: var(--muted);
    font-size: 0.85rem;
}

.summary-item strong {
    font-size: 1.05rem;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    width: fit-content;
    font-size: 0.85rem;
    color: #173224;
    background: rgba(31, 108, 90, 0.12);
}

.pill::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.75;
}

.empty-state,
.error-box {
    padding: 32px;
}

.error-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.error-debug {
    margin-top: 18px;
    padding: 16px;
    background: #f7f9fc;
    border-radius: 14px;
    overflow: auto;
}

.admin-content {
    align-content: start;
}

.admin-grid {
    display: grid;
    gap: 22px;
}

.admin-grid--cards {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

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

.admin-grid--three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.admin-form,
.admin-inline-form {
    display: grid;
    gap: 16px;
}

.admin-inline-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
}

.admin-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.check-field input {
    width: 18px;
    height: 18px;
}

.form-field textarea,
.form-field select {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 14px;
    padding: 0.9rem 1rem;
    color: var(--text);
}

.field-help {
    color: var(--muted);
    font-size: 0.85rem;
}

.admin-table-wrap {
    overflow: auto;
}

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

.admin-table th,
.admin-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    color: var(--muted);
    font-size: 0.84rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-table td input[type="number"] {
    max-width: 110px;
}

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

.admin-row-actions form {
    margin: 0;
}

.admin-note {
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    color: var(--muted);
}

.admin-tabs {
    display: flex;
    gap: 10px;
    padding: 10px;
    border-radius: 18px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.admin-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.admin-tab:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.7);
}

.admin-tab.is-active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 8px 20px rgba(22, 32, 51, 0.08);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.status-badge__dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    flex: 0 0 10px;
    box-shadow: 0 0 0 3px rgba(22, 32, 51, 0.05);
}

.status-badge.is-active .status-badge__dot {
    background: #2f6f4f;
}

.status-badge.is-inactive .status-badge__dot {
    background: #d96c42;
}

.status-badge.is-active {
    color: #2f6f4f;
}

.status-badge.is-inactive {
    color: #b6542f;
}

.admin-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: grid;
    place-items: center;
    padding: 24px;
}

.admin-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    backdrop-filter: blur(3px);
}

.admin-modal__dialog {
    position: relative;
    width: min(760px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    border-radius: 24px;
    border: 1px solid rgba(22, 32, 51, 0.1);
    background: #fff;
    box-shadow: 0 28px 60px rgba(15, 23, 42, 0.22);
}

.admin-modal__header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
}

.admin-modal__header h3 {
    margin: 0;
    font-size: 1.15rem;
}

.admin-modal__body {
    padding: 24px;
}

.password-feedback {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    display: grid;
    gap: 10px;
}

.password-feedback.is-valid {
    border-color: rgba(47, 111, 79, 0.35);
    background: rgba(110, 169, 122, 0.12);
}

.password-feedback.is-invalid {
    border-color: rgba(217, 108, 66, 0.35);
    background: rgba(217, 108, 66, 0.08);
}

.password-rules {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.password-rules li {
    position: relative;
    padding-left: 24px;
    color: var(--muted);
    transition: color 0.18s ease;
}

.password-rules li::before {
    content: "○";
    position: absolute;
    left: 0;
    top: 0;
    font-weight: 700;
    transition: color 0.18s ease, transform 0.18s ease;
}

.password-rules li.is-valid {
    color: #2f6f4f;
    font-weight: 600;
}

.password-rules li.is-valid::before {
    content: "✓";
    color: #2f6f4f;
    transform: scale(1.05);
}

.password-rules li.is-invalid {
    color: #d96c42;
    font-weight: 600;
}

.password-rules li.is-invalid::before {
    content: "✕";
    color: #d96c42;
}

.password-feedback__message {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.password-feedback.is-valid .password-feedback__message {
    color: #2f6f4f;
}

.password-feedback.is-invalid .password-feedback__message {
    color: #d96c42;
}

.sortable-pages {
    display: grid;
    gap: 12px;
}

.sortable-page-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #fff;
    cursor: grab;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.sortable-page-card:hover {
    border-color: rgba(47, 111, 79, 0.3);
}

.sortable-page-card.is-dragging {
    opacity: 0.72;
    transform: scale(0.995);
    box-shadow: 0 12px 32px rgba(22, 32, 51, 0.12);
}

.sortable-page-card.is-drop-target {
    border-color: rgba(47, 111, 79, 0.45);
    box-shadow: 0 10px 24px rgba(47, 111, 79, 0.12);
}

.sortable-page-card__handle {
    color: var(--muted);
    font-size: 1.2rem;
    line-height: 1;
    letter-spacing: 0.08em;
    user-select: none;
}

.sortable-page-card__content {
    display: grid;
    gap: 4px;
}

.sortable-page-card__content small {
    color: var(--muted);
}

.sortable-page-card__visibility {
    justify-self: start;
}

.sortable-page-card__meta {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-self: end;
}

.sortable-page-card__position {
    color: var(--muted);
    font-size: 0.9rem;
    white-space: nowrap;
}

.admin-thresholds {
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    display: grid;
    gap: 14px;
}

.admin-thresholds legend {
    padding: 0 8px;
    font-weight: 700;
}

.admin-sidebar .sidebar__nav {
    align-content: start;
}

.sidebar__logout {
    display: grid;
    gap: 10px;
}

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

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

    .widget-card.span-3 {
        grid-column: span 2;
    }

    .admin-grid--two,
    .admin-grid--three {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .admin-modal {
        padding: 12px;
    }

    .admin-modal__dialog {
        width: 100%;
        max-height: calc(100vh - 24px);
        border-radius: 20px;
    }

    .admin-modal__header,
    .admin-modal__body {
        padding: 18px;
    }

    .admin-modal__header {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 720px) {
    .login-page,
    .dashboard-page {
        padding: 16px;
    }

    .login-brand__cards,
    .widget-grid {
        grid-template-columns: 1fr;
    }

    .widget-card.span-2,
    .widget-card.span-3 {
        grid-column: span 1;
    }

    .dashboard-header,
    .widget-card__header {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-inline-form {
        grid-template-columns: 1fr;
    }

    .sortable-page-card {
        grid-template-columns: auto 1fr;
    }

    .sortable-page-card__visibility,
    .sortable-page-card__meta {
        grid-column: 1 / -1;
    }

    .sortable-page-card__meta {
        justify-self: stretch;
        justify-content: space-between;
    }
}
