:root {
    --green-700: #1a6b3c;
    --green-600: #24884a;
    --green-500: #2ea85c;
    --green-400: #4bc878;
    --green-100: #e6f4eb;
    --green-50: #f2faf5;
    --grey-900: #1e2429;
    --grey-800: #2d353c;
    --grey-700: #454f59;
    --grey-500: #7a8794;
    --grey-300: #c5cdd4;
    --grey-200: #dfe4e8;
    --grey-100: #eef1f4;
    --grey-50: #f7f9fa;
    --white: #ffffff;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 2px 8px rgba(30, 36, 41, 0.06);
    --shadow-md: 0 8px 24px rgba(30, 36, 41, 0.08);
    --shadow-lg: 0 16px 40px rgba(30, 36, 41, 0.1);
    --transition: 0.22s ease;
    --header-h: 64px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: Tahoma, "Segoe UI", Arial, sans-serif;
    margin: 0;
    background: linear-gradient(160deg, var(--grey-100) 0%, var(--grey-50) 45%, #e9efe9 100%);
    background-attachment: fixed;
    color: var(--grey-900);
    line-height: 1.55;
    min-height: 100vh;
}

a { color: var(--green-700); transition: color var(--transition); }
a:hover { color: var(--green-500); }

/* ── Header ── */
.panel-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(135deg, var(--grey-800) 0%, var(--grey-900) 100%);
    color: var(--white);
    box-shadow: var(--shadow-md);
    border-bottom: 3px solid var(--green-500);
}

.panel-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: var(--header-h);
}

.panel-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-shrink: 0;
}

.panel-brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--green-500), var(--green-700));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(46, 168, 92, 0.35);
}

.panel-brand-text strong { display: block; font-size: .95rem; }
.panel-brand-text span { font-size: .75rem; color: var(--grey-300); }

.nav-toggle {
    display: none;
    margin-right: auto;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    color: var(--white);
    border-radius: var(--radius-sm);
    padding: .45rem .65rem;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: background var(--transition);
}
.nav-toggle:hover { background: rgba(255,255,255,.15); }

.panel-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .25rem;
    flex: 1;
}

.panel-nav a {
    color: var(--grey-300);
    text-decoration: none;
    padding: .45rem .75rem;
    border-radius: var(--radius-sm);
    font-size: .82rem;
    transition: all var(--transition);
    white-space: nowrap;
}
.panel-nav a:hover {
    color: var(--white);
    background: rgba(255,255,255,.08);
}
.panel-nav a.active {
    color: var(--white);
    background: linear-gradient(135deg, var(--green-600), var(--green-700));
    box-shadow: 0 2px 8px rgba(36, 136, 74, 0.4);
}
.panel-nav a.nav-logout {
    margin-right: auto;
    color: #f5a8a0;
}
.panel-nav a.nav-logout:hover {
    background: rgba(192, 57, 43, 0.25);
    color: #fff;
}

/* ── Layout ── */
.wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem 2.5rem;
}

.page-enter {
    animation: pageIn 0.45s ease both;
}

@keyframes pageIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Cards ── */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.35rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(197, 205, 212, 0.5);
    transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

.card h1, .card h2 {
    margin-top: 0;
    font-size: 1.2rem;
    color: var(--grey-800);
    padding-bottom: .65rem;
    border-bottom: 2px solid var(--green-100);
    margin-bottom: 1rem;
}

.card h1::before, .card h2::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 1em;
    background: var(--green-500);
    border-radius: 4px;
    margin-left: .5rem;
    vertical-align: middle;
}

/* ── Typography ── */
.muted { color: var(--grey-500); font-size: .85rem; }
code {
    background: var(--grey-100);
    padding: .15rem .45rem;
    border-radius: 6px;
    font-size: .9em;
    color: var(--green-700);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: .85rem;
    font-family: inherit;
    text-decoration: none;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--green-500), var(--green-700));
    color: var(--white);
}
.btn-primary:hover { color: var(--white); filter: brightness(1.05); }

.btn-success {
    background: linear-gradient(135deg, #3cb371, var(--green-600));
    color: var(--white);
}
.btn-success:hover { color: var(--white); }

.btn-danger {
    background: linear-gradient(135deg, #e74c3c, var(--danger));
    color: var(--white);
}
.btn-danger:hover { color: var(--white); }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 8px; }

/* ── Forms ── */
label {
    display: block;
    margin: .65rem 0 .3rem;
    font-size: .85rem;
    color: var(--grey-700);
    font-weight: 600;
}

input, select, textarea {
    padding: .55rem .75rem;
    border: 1.5px solid var(--grey-200);
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 360px;
    font-family: inherit;
    font-size: .9rem;
    background: var(--grey-50);
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--green-400);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(46, 168, 92, 0.15);
}
textarea { max-width: 100%; font-family: inherit; resize: vertical; }
form.inline { display: inline; }

.input-money { direction: ltr; text-align: left; }

/* ── Flash ── */
.flash {
    padding: .85rem 1.1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    animation: slideDown 0.35s ease;
    border: 1px solid transparent;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.flash-ok {
    background: var(--green-50);
    color: var(--green-700);
    border-color: rgba(46, 168, 92, 0.25);
}
.flash-err {
    background: var(--danger-bg);
    color: #922b21;
    border-color: rgba(192, 57, 43, 0.2);
}
.flash-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: .6;
    padding: 0 .25rem;
    line-height: 1;
}
.flash-close:hover { opacity: 1; }
.flash.is-hiding {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.35s, transform 0.35s;
}

/* ── Stats grid ── */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: .85rem;
}
.stat {
    background: linear-gradient(145deg, var(--grey-50), var(--white));
    padding: 1.1rem .9rem;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--grey-200);
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
    opacity: 0;
    transform: translateY(10px);
}
.stat.is-visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease, border-color var(--transition), box-shadow var(--transition);
}
.stat:hover {
    border-color: var(--green-400);
    box-shadow: 0 4px 16px rgba(46, 168, 92, 0.12);
    transform: translateY(-2px);
}
.stat b {
    display: block;
    font-size: 1.35rem;
    color: var(--green-700);
    margin-bottom: .25rem;
    font-weight: 700;
}
.stat span, .stat { font-size: .78rem; color: var(--grey-500); }

/* ── Tables ── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--grey-200);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
th, td {
    padding: .65rem .85rem;
    text-align: right;
    border-bottom: 1px solid var(--grey-200);
}
th {
    background: linear-gradient(180deg, var(--grey-100), var(--grey-50));
    color: var(--grey-700);
    font-weight: 600;
    font-size: .82rem;
    white-space: nowrap;
}
tbody tr {
    transition: background var(--transition);
}
tbody tr:hover { background: var(--green-50); }
tbody tr:last-child td { border-bottom: none; }

/* ── Chart ── */
.chart-wrap {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 220px;
    padding: 1rem .5rem 0;
    overflow-x: auto;
    background: var(--grey-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--grey-200);
}
.chart-col {
    flex: 1;
    min-width: 20px;
    max-width: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    cursor: default;
}
.chart-bar {
    width: 100%;
    background: linear-gradient(180deg, var(--green-400), var(--green-700));
    border-radius: 8px 8px 4px 4px;
    min-height: 4px;
    height: 0;
    transition: height 0.6s cubic-bezier(0.34, 1.4, 0.64, 1), filter var(--transition);
}
.chart-col:hover .chart-bar { filter: brightness(1.1); }
.chart-label {
    font-size: .62rem;
    color: var(--grey-500);
    margin-top: 6px;
    white-space: nowrap;
}
.chart-tooltip {
    position: fixed;
    background: var(--grey-900);
    color: var(--white);
    padding: .4rem .65rem;
    border-radius: 8px;
    font-size: .75rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 200;
    box-shadow: var(--shadow-lg);
}
.chart-tooltip.is-show { opacity: 1; }

/* ── Settings / packages ── */
.settings-group h2 { font-size: 1.05rem; margin-bottom: .75rem; border-bottom: none; padding-bottom: 0; }
.settings-group h2::before { display: none; }
.setting-item {
    border: 1.5px solid var(--grey-200);
    border-radius: var(--radius-md);
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
    background: var(--grey-50);
}
.setting-item legend { padding: 0 .35rem; font-weight: 600; color: var(--grey-800); }
.setting-hint { margin: 0 0 .5rem; }
.setting-item textarea { min-height: 110px; }

.package-row {
    border-bottom: 1px solid var(--grey-200);
    padding: 1.15rem 0;
    transition: background var(--transition);
    border-radius: var(--radius-sm);
    padding-left: .5rem;
    padding-right: .5rem;
}
.package-row:hover { background: var(--green-50); }
.package-row:last-child { border-bottom: none; }

/* ── Badges & links ── */
.tg-link {
    color: var(--green-700);
    font-weight: 600;
    text-decoration: none;
    padding: .15rem .4rem;
    border-radius: 6px;
    transition: all var(--transition);
}
.tg-link:hover {
    background: var(--green-100);
    text-decoration: none;
}
.badge-blocked {
    background: var(--danger-bg);
    color: #922b21;
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-ok {
    background: var(--green-100);
    color: var(--green-700);
    padding: .2rem .55rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}

.status-toggle {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--grey-200);
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.status-toggle:hover { background: var(--green-50); }
.status-toggle input { width: auto; max-width: none; accent-color: var(--green-600); }

/* ── Login ── */
.login-page .wrap { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 2rem); }
.login-box {
    max-width: 440px;
    width: 100%;
    text-align: center;
    padding: 2rem 1.75rem !important;
}
.login-box h1 { border-bottom: none; }
.login-box h1::before { display: none; }
.login-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 18px;
    background: linear-gradient(145deg, var(--green-500), var(--green-700));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    box-shadow: 0 8px 24px rgba(46, 168, 92, 0.3);
}
.login-steps {
    text-align: right;
    line-height: 1.9;
    background: var(--grey-50);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    border: 1px solid var(--grey-200);
}

/* ── Search bar ── */
.search-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .65rem;
    align-items: center;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--grey-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--grey-200);
}
.search-bar input { flex: 1; min-width: 200px; max-width: none; margin: 0; }

/* ── Loading overlay for forms ── */
.btn.is-loading {
    pointer-events: none;
    opacity: .75;
    position: relative;
}
.btn.is-loading::after {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: .35rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 900px) {
    .nav-toggle { display: block; }
    .panel-nav {
        display: none;
        position: absolute;
        top: var(--header-h);
        left: 0;
        right: 0;
        background: var(--grey-900);
        flex-direction: column;
        align-items: stretch;
        padding: .75rem;
        gap: .15rem;
        box-shadow: var(--shadow-lg);
        border-bottom: 3px solid var(--green-500);
    }
    .panel-nav.is-open { display: flex; }
    .panel-nav a {
        padding: .65rem .85rem;
        border-radius: var(--radius-sm);
    }
    .panel-nav a.nav-logout { margin-right: 0; margin-top: .5rem; }
    .panel-header-inner { position: relative; flex-wrap: wrap; }
    input, select, textarea { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

.perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.perm-section {
    border: 1px solid var(--grey-200);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    margin: 0;
    background: var(--grey-50);
}

.perm-section legend {
    font-weight: 600;
    padding: 0 .35rem;
}

.perm-check {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    margin: .45rem 0;
    font-size: .92rem;
    cursor: pointer;
}

.perm-check input {
    margin-top: .2rem;
    width: auto;
    max-width: none;
}
