:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafb;
    --line: #dfe4e8;
    --line-strong: #cbd2d8;
    --text: #18212a;
    --muted: #66727e;
    --nav: #172027;
    --nav-muted: #aeb8c0;
    --primary: #087f6b;
    --primary-hover: #066a5a;
    --danger: #c83b3b;
    --danger-soft: #fff0ef;
    --warning: #9a6200;
    --warning-soft: #fff8e7;
    --success: #167347;
    --success-soft: #edf8f2;
    --shadow: 0 10px 28px rgba(25, 35, 43, .08);
    font-family: Tahoma, Arial, sans-serif;
    font-size: 14px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.55; overflow-x: hidden; }
button, input, select, textarea { color: inherit; font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
svg { width: 18px; height: 18px; stroke-width: 1.8; flex: 0 0 auto; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 24px; line-height: 1.35; }
h2 { margin-bottom: 14px; font-size: 17px; line-height: 1.4; }
p { color: var(--muted); }
small { color: var(--muted); }

.app-shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; z-index: 30; display: flex; flex-direction: column; height: 100vh; padding: 18px 14px; background: var(--nav); color: #fff; }
.brand, .login-brand { display: flex; align-items: center; gap: 10px; min-height: 42px; font-size: 17px; font-weight: 700; }
.brand { padding: 0 9px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; background: #11a58d; color: #fff; font-weight: 800; }
.nav { display: grid; gap: 4px; margin-top: 18px; }
.nav a { display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 8px 11px; border-radius: 6px; color: var(--nav-muted); }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: #27343d; color: #fff; box-shadow: inset -3px 0 #19ad94; }
.sidebar-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding: 14px 9px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer .user-name { min-width: 0; overflow: hidden; color: #d8dee3; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer .icon-button { border-color: rgba(255,255,255,.14); color: #d8dee3; }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; height: 62px; padding: 0 clamp(18px, 2.5vw, 42px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.topbar-title { font-size: 15px; font-weight: 700; }
.topbar-status { display: flex; align-items: center; gap: 7px; margin-right: auto; color: var(--muted); font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #23a66b; box-shadow: 0 0 0 3px #e0f4ea; }
.icon-button.mobile-menu { display: none; }
.content { width: 100%; max-width: 1680px; margin: 0 auto; padding: 28px clamp(18px, 2.5vw, 42px) 48px; }

.page-heading, .section-header, .dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.page-heading { margin-bottom: 22px; }
.page-heading p, .section-header h2 { margin-bottom: 0; }
.page-heading p { font-size: 13px; }
.section-block { margin-top: 28px; }
.section-header { margin-bottom: 12px; }
.section-header h2 { font-size: 16px; }

.button, .icon-button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 6px; cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease, opacity .15s ease; }
.button { gap: 8px; min-height: 38px; padding: 7px 13px; font-weight: 700; white-space: nowrap; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover { background: var(--primary-hover); color: #fff; }
.button-secondary { border-color: var(--line-strong); background: var(--surface); color: var(--text); }
.button-secondary:hover { border-color: #9eabb5; background: var(--surface-muted); color: var(--text); }
.button-danger { border-color: #efc0bd; background: var(--danger-soft); color: #a82e2e; }
.button-danger:hover { border-color: #dc8d88; color: #8e2323; }
.button-wide { width: 100%; }
.button:disabled, .icon-button:disabled { cursor: wait; opacity: .65; }
.is-busy svg { animation: spin .8s linear infinite; }
.icon-button { width: 34px; height: 34px; padding: 0; border-color: var(--line); background: var(--surface); color: #4d5a65; }
.icon-button:hover { border-color: #aeb8c0; background: var(--surface-muted); color: var(--text); }
.icon-button.danger { color: var(--danger); }
.icon-button.console { color: #305ea8; }
.icon-button.muted { opacity: .48; }

.notice { margin-bottom: 18px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.notice-success { border-color: #b9dfca; background: var(--success-soft); color: #105f3a; }
.notice-error { border-color: #edc0bc; background: var(--danger-soft); color: #962b2b; }
.notice-warning { border-color: #ead69f; background: var(--warning-soft); color: #79500a; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.stats-grid article { position: relative; min-width: 0; min-height: 108px; padding: 20px; border-left: 1px solid var(--line); }
.stats-grid article:last-child { border-left: 0; }
.stats-grid article > span { display: block; color: var(--muted); font-size: 12px; }
.stats-grid article strong { display: block; margin-top: 8px; font-size: 28px; line-height: 1; }
.stats-grid article svg { position: absolute; top: 21px; left: 20px; color: #89959e; }

.provider-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.provider-item { padding: 16px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.provider-name, .account-provider { display: flex; align-items: center; gap: 11px; min-width: 0; }
.provider-badge { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; background: #e7ecef; color: #33404a; font-weight: 800; }
.provider-hetzner { background: #fff0f0; color: #ba2828; }
.provider-leaseweb { background: #e8f8f5; color: #08735f; }
.provider-ovh { background: #edf3ff; color: #285aa5; }
.provider-item dl { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0 0; }
.provider-item dl div { border-right: 1px solid var(--line); text-align: center; }
.provider-item dl div:first-child { border-right: 0; }
.provider-item dt { color: var(--muted); font-size: 11px; }
.provider-item dd { margin: 3px 0 0; font-weight: 700; }

.table-wrap { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); overflow: hidden; }
.data-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 12px; }
.data-table th { padding: 10px 9px; border-bottom: 1px solid var(--line); background: var(--surface-muted); color: #596670; text-align: right; font-size: 11px; font-weight: 700; }
.data-table td { min-width: 0; padding: 11px 9px; border-bottom: 1px solid #e9edef; vertical-align: middle; overflow-wrap: anywhere; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fbfcfc; }
.data-table td > strong, .data-table td > span, .data-table td > small { display: block; }
.data-table td > small { margin-top: 3px; font-size: 10px; }
.server-table th:nth-child(1) { width: 13%; }
.server-table th:nth-child(2) { width: 10%; }
.server-table th:nth-child(3) { width: 8%; }
.server-table th:nth-child(4) { width: 13%; }
.server-table th:nth-child(5) { width: 15%; }
.server-table th:last-child { width: 160px; }
.mono { direction: ltr; font-family: Consolas, monospace; text-align: left; }
.provider-pill { display: inline-flex !important; width: fit-content; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.status { display: inline-flex !important; align-items: center; gap: 6px; width: fit-content; white-space: nowrap; font-size: 11px; font-weight: 700; }
.status > span { width: 7px; height: 7px; border-radius: 50%; background: #8f99a2; }
.status-running { color: var(--success); }
.status-running > span { background: #20a366; }
.status-stopped { color: #a33333; }
.status-stopped > span { background: #d04747; }
.status-pending { color: #7b5a16; }
.status-pending > span { background: #c08a20; }
.action-group, .account-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.action-group form, .account-actions form { display: contents; }

.filters { display: grid; grid-template-columns: minmax(220px, 1fr) 190px 170px auto; gap: 9px; margin-bottom: 14px; }
.filters input, .filters select, .filters .button { min-height: 40px; }
.search-field { position: relative; }
.search-field svg { position: absolute; top: 11px; right: 11px; color: #7a8791; }
.search-field input { width: 100%; padding-right: 38px; }

input, select, textarea { width: 100%; min-height: 40px; margin-top: 6px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 5px; outline: none; background: #fff; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(8,127,107,.11); }
label { display: block; color: #34414b; font-size: 12px; font-weight: 700; }
.optional { color: var(--muted); font-size: 10px; font-weight: 400; }
.form-stack { display: grid; gap: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.settings-form { display: grid; gap: 14px; }
.form-section { padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.form-section[hidden] { display: none; }
.form-actions { display: flex; justify-content: flex-start; }
.settings-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.session-section { grid-column: 1 / -1; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 28px; padding: 17px; border: 1px solid #edc0bc; border-radius: 7px; background: #fffafa; }
.danger-zone h2, .danger-zone p { margin-bottom: 2px; }
.totp-secret { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 9px; border: 1px solid var(--line); background: var(--surface-muted); }
.totp-secret code { direction: ltr; min-width: 0; overflow-wrap: anywhere; }
.totp-secret .icon-button { margin-right: auto; }
.muted-text { font-size: 12px; }
.recovery-codes { margin-top: 14px; padding: 12px; border: 1px solid #ead69f; background: var(--warning-soft); }
.recovery-codes div { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; direction: ltr; }
.recovery-codes code { padding: 4px 7px; background: #fff; }

.account-list { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.account-row { display: grid; grid-template-columns: minmax(210px, 1.2fr) minmax(170px, 1fr) minmax(210px, 1fr) auto; align-items: center; gap: 16px; min-height: 82px; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.account-row:last-child { border-bottom: 0; }
.account-provider > div, .account-health { min-width: 0; }
.account-provider strong, .account-provider small, .account-health small, .account-times span { display: block; }
.account-provider small, .account-health small, .account-times { color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.account-health small { margin-top: 4px; }
.account-times { display: grid; gap: 3px; }

.dialog { width: min(440px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 7px; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(13,20,25,.58); }
.dialog form { padding: 18px; }
.dialog-heading h2 { margin-bottom: 0; }
.empty-state { display: grid; place-items: center; min-height: 180px; padding: 30px; color: var(--muted); text-align: center; }
.empty-state svg { width: 28px; height: 28px; margin-bottom: 9px; }
.empty-state strong { color: #3c4852; }
.empty-state span { font-size: 12px; }
.outcome { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.outcome-success { background: var(--success-soft); color: var(--success); }
.outcome-failure { background: var(--danger-soft); color: var(--danger); }

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 22px; background: #e9eef1; }
.auth-shell { width: min(400px, 100%); }
.login-panel { padding: 28px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.login-brand { margin-bottom: 28px; color: #26333c; }
.login-panel h1 { font-size: 21px; }
.login-panel > p { margin-bottom: 20px; font-size: 12px; }

.error-page { display: grid; place-items: center; min-height: 55vh; text-align: center; }
.error-page > span { color: var(--primary); font-size: 42px; font-weight: 800; }

.console-page { min-height: 100vh; background: #0d1216; color: #edf2f5; }
.console-shell { display: grid; grid-template-rows: 52px minmax(0, 1fr) 30px; height: 100vh; }
.console-shell header { display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-bottom: 1px solid #303b43; background: #171f25; }
.console-shell header > div { display: flex; gap: 11px; }
.console-shell header span, .console-shell footer { color: #9eabb4; font-size: 12px; }
.console-shell .icon-button { border-color: #3a464e; background: #222c33; color: #dfe6ea; }
.console-screen { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #050708; }
.console-screen canvas { width: 100% !important; height: 100% !important; object-fit: contain; }
.console-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; color: #aeb9c0; }
.console-shell footer { display: flex; align-items: center; padding: 0 12px; border-top: 1px solid #303b43; background: #171f25; }
.spinner { width: 18px; height: 18px; border: 2px solid #4e5c65; border-top-color: #2dc0a7; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
    .app-shell { grid-template-columns: 208px minmax(0, 1fr); }
    .sidebar { padding-right: 10px; padding-left: 10px; }
    .server-table { font-size: 11px; }
    .server-table th:last-child { width: 122px; }
    .icon-button { width: 31px; height: 31px; }
    .action-group { gap: 3px; }
    .account-row { grid-template-columns: minmax(190px, 1fr) minmax(150px, 1fr) minmax(190px, 1fr) auto; gap: 10px; }
}

@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar { position: fixed; right: 0; width: 236px; transform: translateX(105%); transition: transform .18s ease; box-shadow: -15px 0 34px rgba(0,0,0,.2); }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open::after { position: fixed; inset: 0; z-index: 25; content: ''; background: rgba(10,15,18,.42); }
    .icon-button.mobile-menu { display: inline-flex; }
    .topbar { padding: 0 16px; }
    .content { padding: 22px 16px 40px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats-grid article:nth-child(2) { border-left: 0; }
    .stats-grid article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .provider-grid { grid-template-columns: 1fr; }
    .account-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .account-actions { justify-content: flex-end; }
    .filters { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .filters .button { width: 100%; }
}

@media (max-width: 680px) {
    h1 { font-size: 20px; }
    .page-heading { align-items: flex-start; }
    .page-heading .button span { display: none; }
    .page-heading .button { width: 38px; padding: 0; }
    .stats-grid article { min-height: 92px; padding: 16px; }
    .stats-grid article svg { top: 17px; left: 16px; }
    .form-grid, .settings-layout { grid-template-columns: 1fr; }
    .session-section { grid-column: auto; }
    .danger-zone { align-items: stretch; flex-direction: column; }
    .filters { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .account-list, .table-wrap { border: 0; background: transparent; }
    .account-row { grid-template-columns: 1fr; margin-bottom: 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
    .account-actions { justify-content: flex-start; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table thead { display: none; }
    .data-table tr { margin-bottom: 10px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
    .data-table td { display: grid; grid-template-columns: 105px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid #edf0f2; text-align: right; }
    .data-table td::before { content: attr(data-label); color: var(--muted); font-size: 10px; }
    .data-table td:last-child { border-bottom: 0; }
    .data-table .mono { direction: rtl; }
    .data-table .mono > * { direction: ltr; text-align: left; }
    .action-group { justify-content: flex-start; }
    .audit-table td { overflow-wrap: anywhere; }
    .topbar-status { font-size: 0; }
    .topbar-status .live-dot { display: block; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
