:root {
    color-scheme: light;
    --page: #eef5f3;
    --surface: #ffffff;
    --surface-soft: #f4f8f7;
    --text: #142824;
    --muted: #647772;
    --line: #dce8e5;
    --primary: #0f766e;
    --primary-dark: #0a5e58;
    --primary-soft: #d8f2ed;
    --accent: #f59e0b;
    --danger: #c2413a;
    --danger-soft: #fde8e6;
    --shadow: 0 18px 48px rgba(22, 58, 52, 0.10);
    --radius: 20px;
    font-family: Tahoma, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--page);
}

body {
    min-width: 280px;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 10% 0%, rgba(15, 118, 110, 0.14), transparent 34%),
        radial-gradient(circle at 100% 25%, rgba(245, 158, 11, 0.10), transparent 30%),
        var(--page);
}

button,
input,
textarea {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: env(safe-area-inset-top) 16px calc(32px + env(safe-area-inset-bottom));
}

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    padding: 14px 0;
}

.brand-mark {
    display: grid;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 15px;
    color: #fff;
    background: linear-gradient(145deg, var(--primary), #159b8f);
    box-shadow: 0 10px 24px rgba(15, 118, 110, 0.24);
    font-size: 21px;
    font-weight: 800;
}

.brand-copy {
    min-width: 0;
}

.brand-copy h1,
.panel-heading h2,
.dialog-header h2 {
    margin: 2px 0 0;
    letter-spacing: -0.03em;
}

.brand-copy h1 {
    font-size: 20px;
}

.eyebrow {
    margin: 0;
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 150px;
    margin-right: auto;
    padding: 6px 8px 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.66);
    box-shadow: 0 6px 24px rgba(22, 58, 52, 0.06);
    font-size: 12px;
    font-weight: 700;
}

.user-chip > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-initial {
    display: grid;
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.state-panel {
    display: grid;
    min-height: 62vh;
    place-items: center;
    align-content: center;
    padding: 32px;
    text-align: center;
}

.state-panel h2 {
    margin: 20px 0 8px;
    font-size: 20px;
}

.state-panel p {
    max-width: 420px;
    margin: 0;
    color: var(--muted);
    line-height: 1.8;
}

.state-panel.is-error .loader {
    display: grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border: 0;
    border-radius: 18px;
    color: var(--danger);
    background: var(--danger-soft);
    animation: none;
}

.state-panel.is-error .loader::after {
    content: "!";
    font-size: 28px;
    font-weight: 900;
}

.loader {
    width: 42px;
    height: 42px;
    border: 4px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 6px 0 14px;
}

.metric {
    min-width: 0;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 10px 30px rgba(22, 58, 52, 0.06);
    backdrop-filter: blur(10px);
}

.metric-primary {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(145deg, var(--primary-dark), var(--primary));
}

.metric span,
.metric small {
    display: block;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.metric-primary span,
.metric-primary small {
    color: rgba(255, 255, 255, 0.72);
}

.metric strong {
    display: block;
    margin: 7px 0 4px;
    font-size: 28px;
    letter-spacing: -0.05em;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 14px;
}

.search-box {
    position: relative;
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
}

.search-box input {
    width: 100%;
    height: 52px;
    padding: 0 44px;
    border: 1px solid var(--line);
    border-radius: 16px;
    outline: none;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 8px 26px rgba(22, 58, 52, 0.05);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.search-icon,
.clear-search {
    position: absolute;
    z-index: 1;
}

.search-icon {
    right: 16px;
    color: var(--muted);
    font-size: 24px;
    transform: rotate(-15deg);
}

.clear-search {
    left: 10px;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    background: var(--surface-soft);
    cursor: pointer;
}

.button {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 0 16px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

.button:active {
    transform: scale(0.98);
}

.button:disabled {
    cursor: wait;
    opacity: 0.55;
}

.button-primary {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 9px 20px rgba(15, 118, 110, 0.20);
}

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

.button-quiet {
    color: var(--primary-dark);
    background: var(--primary-soft);
}

.button-danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.data-panel {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.78);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 12px;
}

.panel-heading h2 {
    font-size: 20px;
}

.result-label {
    color: var(--muted);
    font-size: 11px;
}

.site-cards {
    display: grid;
    gap: 10px;
    padding: 4px 12px 14px;
}

.site-card {
    width: 100%;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 17px;
    color: var(--text);
    background: var(--surface);
    text-align: right;
    cursor: pointer;
}

.site-card:active {
    border-color: var(--primary);
    background: var(--surface-soft);
}

.site-card-head,
.site-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.site-code {
    direction: ltr;
    font-size: 17px;
    font-weight: 900;
    letter-spacing: 0.03em;
}

.badge {
    display: inline-flex;
    min-height: 26px;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-size: 10px;
    font-weight: 800;
}

.site-card-location {
    margin: 9px 0 13px;
    color: var(--muted);
    font-size: 12px;
}

.site-card-foot {
    padding-top: 11px;
    border-top: 1px dashed var(--line);
    color: var(--muted);
    font-size: 11px;
}

.table-wrap {
    display: none;
    overflow-x: auto;
}

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

th,
td {
    padding: 14px 16px;
    border-top: 1px solid var(--line);
    text-align: right;
    white-space: nowrap;
}

th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 11px;
}

td {
    font-size: 12px;
}

tbody tr {
    cursor: pointer;
    transition: background 120ms ease;
}

tbody tr:hover {
    background: var(--surface-soft);
}

.row-action {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    color: var(--primary);
    background: var(--primary-soft);
    cursor: pointer;
    font-weight: 900;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 11px;
}

.page-button {
    min-width: 64px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
}

.page-button:disabled {
    opacity: 0.4;
}

.empty-state {
    padding: 46px 20px;
    text-align: center;
}

.empty-state > span {
    display: block;
    color: var(--primary);
    font-size: 44px;
}

.empty-state h3 {
    margin: 8px 0;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.list-loading {
    display: grid;
    gap: 10px;
    padding: 8px 12px 18px;
}

.skeleton {
    height: 112px;
    border-radius: 17px;
    background: linear-gradient(90deg, var(--surface-soft), #e5eeec, var(--surface-soft));
    background-size: 220% 100%;
    animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
    to { background-position: -220% 0; }
}

.site-dialog {
    width: min(760px, 100%);
    max-width: 100%;
    height: min(94vh, 940px);
    max-height: 94vh;
    margin: auto auto 0;
    padding: 0;
    border: 0;
    border-radius: 26px 26px 0 0;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 -20px 60px rgba(10, 42, 37, 0.24);
}

.site-dialog::backdrop {
    background: rgba(7, 34, 31, 0.52);
    backdrop-filter: blur(4px);
}

.site-dialog form {
    display: flex;
    height: 100%;
    flex-direction: column;
}

.dialog-header {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 15px 16px;
    border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
    font-size: 18px;
}

.icon-button {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    color: var(--muted);
    background: var(--surface-soft);
    cursor: pointer;
    font-size: 22px;
}

.form-status {
    color: var(--muted);
    font-size: 10px;
}

.form-fields {
    overflow-y: auto;
    flex: 1;
    padding: 14px 14px 28px;
}

.field-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface-soft);
}

.field-group h3 {
    grid-column: 1 / -1;
    margin: 0 0 2px;
    color: var(--primary);
    font-size: 13px;
}

.field {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.field label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}

.field input,
.field textarea {
    width: 100%;
    min-height: 45px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    color: var(--text);
    background: var(--surface);
}

.field textarea {
    min-height: 84px;
    resize: vertical;
    line-height: 1.7;
}

.field input:focus,
.field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.field input[dir="ltr"],
.field textarea[dir="ltr"] {
    text-align: left;
}

.dialog-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.dialog-action-group {
    display: flex;
    gap: 8px;
    margin-right: auto;
}

.toast-region {
    position: fixed;
    z-index: 100;
    right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    left: 16px;
    display: grid;
    justify-items: center;
    pointer-events: none;
}

.toast {
    width: min(420px, 100%);
    padding: 13px 16px;
    border-radius: 14px;
    color: #fff;
    background: #173c37;
    box-shadow: 0 16px 36px rgba(4, 29, 26, 0.26);
    font-size: 12px;
    line-height: 1.7;
    animation: toast-in 180ms ease-out;
}

.toast.is-error {
    background: #8f332e;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(10px); }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

[hidden] {
    display: none !important;
}

@media (min-width: 720px) {
    .app-shell {
        padding-right: 24px;
        padding-left: 24px;
    }

    .topbar {
        min-height: 88px;
    }

    .brand-copy h1 {
        font-size: 24px;
    }

    .summary {
        grid-template-columns: 220px 220px;
        justify-content: start;
    }

    .toolbar {
        grid-template-columns: minmax(280px, 1fr) auto auto;
    }

    .search-box {
        grid-column: auto;
    }

    .site-cards {
        display: none;
    }

    .table-wrap {
        display: block;
    }

    .skeleton {
        height: 58px;
    }

    .site-dialog {
        height: min(90vh, 900px);
        margin: auto;
        border-radius: 26px;
    }

    .field-group {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 18px;
    }

    .field.is-wide {
        grid-column: 1 / -1;
    }
}

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

