:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --ink: #1e293b;
    --muted: #64748b;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-soft: #ccfbf1;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --border: #dbe3ea;
    --ring: rgba(15, 118, 110, 0.22);
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Noto Sans", Tahoma, sans-serif;
    line-height: 1.45;
    color: var(--ink);
    background:
        radial-gradient(circle at 0% 0%, #d9f99d 0%, transparent 30%),
        radial-gradient(circle at 100% 10%, #bfdbfe 0%, transparent 28%),
        var(--bg);
}

a {
    color: var(--primary-dark);
}

a:hover {
    color: var(--primary);
}

h1,
h2,
h3 {
    letter-spacing: 0.1px;
}

.topbar {
    background: linear-gradient(120deg, #134e4a, #0f766e);
    color: #fff;
    padding: 20px 24px;
    box-shadow: var(--shadow-sm);
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
}

.topbar p {
    margin: 6px 0 0;
    opacity: 0.9;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: #ecfeff;
    border-bottom: 1px solid #a5f3fc;
    position: sticky;
    top: 0;
    z-index: 30;
    backdrop-filter: blur(4px);
}

.nav a {
    text-decoration: none;
    color: #0f172a;
    font-weight: 600;
    padding: 9px 12px;
    border-radius: var(--radius-md);
    transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-dropdown {
    position: relative;
    display: flex;
    align-items: center;
}

.nav-dropdown-trigger {
    appearance: none;
    font: inherit;
    border: none;
    background: transparent;
    color: #0f172a;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-dropdown-trigger::after {
    content: "▾";
    font-size: 12px;
    line-height: 1;
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 210px;
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 20;
}

.nav-dropdown.open .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
    display: flex;
}

.nav-dropdown-menu a {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-md);
}

.nav-dropdown-menu a:hover,
.nav-dropdown-menu a.active {
    background: #ecfeff;
    color: var(--primary);
}

.nav a.active,
.nav a:hover,
.nav-dropdown.open .nav-dropdown-trigger,
.nav-dropdown.active .nav-dropdown-trigger,
.nav-dropdown-trigger:hover {
    background: var(--primary);
    color: #fff;
}

.container {
    width: min(1400px, 100% - 28px);
    margin: 18px auto 28px;
    display: grid;
    gap: 16px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.card h2,
.card h3 {
    margin-top: 0;
}

.card p {
    margin-top: 0;
}

.collapse-card {
    padding: 0;
    overflow: hidden;
}

.collapse-card summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
}

.collapse-card summary::-webkit-details-marker {
    display: none;
}

.collapse-card summary small {
    font-weight: 600;
    color: var(--muted);
}

.collapse-card[open] summary {
    background: #ecfeff;
}

.collapse-card .table-wrap {
    padding: 12px 16px 16px;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.stats-grid,
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.stat-box,
.summary-grid > div {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    background: #f8fafc;
}

.stat-box span,
.summary-grid span {
    color: var(--muted);
    display: block;
    font-size: 12px;
}

.stat-box strong,
.summary-grid strong {
    font-size: 18px;
}

.summary-grid strong + span {
    margin-top: 4px;
}

.form-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 12px;
    align-items: center;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.inline-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 12px;
    align-items: end;
}

.inline-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

label {
    font-weight: 600;
}

.hint {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #f8fafc;
}

.hint.ok {
    border-color: #99f6e4;
    background: #f0fdfa;
    color: #134e4a;
}

.hint.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.form-grid.compact {
    grid-template-columns: 160px 1fr;
}

input,
select,
button {
    font: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}

input,
select,
textarea {
    background: #fff;
    color: var(--ink);
}

input:focus,
select:focus,
textarea:focus,
button:focus,
.tab-link:focus,
.nav a:focus,
.nav-dropdown-trigger:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--ring);
}

.cell-input {
    width: 110px;
    min-width: 110px;
}

button {
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: filter 0.15s ease, transform 0.05s ease;
}

button:hover {
    filter: brightness(0.95);
}

button:active {
    transform: translateY(1px);
}

button.danger {
    background: var(--danger);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
    background: #fff;
}

th,
td {
    border-bottom: 1px solid var(--border);
    text-align: left;
    padding: 9px 8px;
    font-size: 14px;
}

th {
    background: #f1f5f9;
    position: sticky;
    top: 0;
    z-index: 1;
}

tbody tr:nth-child(even) {
    background: #fafcfd;
}

tbody tr:hover {
    background: #f0fdfa;
}

.index-pattern-table thead th {
    border: 1px solid var(--border);
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    font-weight: 700;
}

.index-pattern-table thead tr:first-child th {
    background: #e5e7eb;
}

.index-pattern-table thead tr:nth-child(2) th {
    background: #f3f4f6;
}

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--primary-soft);
    color: #115e59;
    border-color: #99f6e4;
}

.alert-error {
    background: var(--danger-soft);
    color: #7f1d1d;
    border-color: #fecaca;
}

.notes,
.steps {
    margin: 0;
    padding-left: 18px;
    line-height: 1.6;
}

.tab-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    align-items: center;
}

.tab-link {
    text-decoration: none;
    color: var(--ink);
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 14px;
    font-weight: 600;
    transition: all 0.15s ease;
}

.tab-link:hover,
.tab-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.compact-summary {
    grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
}

.filter-form-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr)) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
}

.filter-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
}

.filter-field input,
.filter-field select {
    width: 100%;
}

.filter-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: #fff;
    text-decoration: none;
    color: var(--ink);
    font-weight: 600;
}

.btn-ghost:hover {
    background: #f8fafc;
}

table.sticky-cols-2 {
    --sticky-col-1-width: 120px;
    --sticky-col-2-width: 220px;
}

table.sticky-cols-2 > thead > tr:first-child > th:nth-child(1),
table.sticky-cols-2 > tbody > tr > td:nth-child(1),
table.sticky-cols-2 > tfoot > tr > td:nth-child(1) {
    position: sticky;
    left: 0;
    min-width: var(--sticky-col-1-width);
    max-width: var(--sticky-col-1-width);
    z-index: 2;
}

table.sticky-cols-2 > thead > tr:first-child > th:nth-child(2),
table.sticky-cols-2 > tbody > tr > td:nth-child(2),
table.sticky-cols-2 > tfoot > tr > td:nth-child(2) {
    position: sticky;
    left: var(--sticky-col-1-width);
    min-width: var(--sticky-col-2-width);
    z-index: 2;
}

table.sticky-cols-2 > thead > tr:first-child > th:nth-child(1),
table.sticky-cols-2 > thead > tr:first-child > th:nth-child(2) {
    z-index: 3;
}

table.sticky-cols-2 > tbody > tr > td:nth-child(1),
table.sticky-cols-2 > tbody > tr > td:nth-child(2),
table.sticky-cols-2 > tfoot > tr > td:nth-child(1),
table.sticky-cols-2 > tfoot > tr > td:nth-child(2) {
    background: #fff;
}

table.sticky-cols-2 > tbody > tr:nth-child(even) > td:nth-child(1),
table.sticky-cols-2 > tbody > tr:nth-child(even) > td:nth-child(2) {
    background: #fafcfd;
}

table.sticky-cols-2 > tbody > tr:hover > td:nth-child(1),
table.sticky-cols-2 > tbody > tr:hover > td:nth-child(2) {
    background: #f0fdfa;
}

table.sticky-cols-2 > thead > tr:first-child > th:nth-child(1)::after,
table.sticky-cols-2 > thead > tr:first-child > th:nth-child(2)::after,
table.sticky-cols-2 > tbody > tr > td:nth-child(1)::after,
table.sticky-cols-2 > tbody > tr > td:nth-child(2)::after,
table.sticky-cols-2 > tfoot > tr > td:nth-child(1)::after,
table.sticky-cols-2 > tfoot > tr > td:nth-child(2)::after {
    content: "";
    position: absolute;
    right: -1px;
    top: 0;
    height: 100%;
    border-right: 1px solid var(--border);
    pointer-events: none;
}

.table-wrap form {
    margin: 0;
}

.action-buttons {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.action-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--ink);
    text-decoration: none;
    font-size: 16px;
    line-height: 1;
    padding: 0;
}

button.action-icon {
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--ink);
    transform: none;
}

.action-icon:hover,
button.action-icon:hover {
    background: #f8fafc;
    filter: none;
}

.action-edit {
    color: #0f766e;
    border-color: #99f6e4;
    background: #f0fdfa;
}

.action-view {
    color: #1d4ed8;
    border-color: #bfdbfe;
    background: #eff6ff;
}

.action-delete {
    color: #b91c1c;
    border-color: #fecaca;
    background: #fef2f2;
}

.action-edit:hover {
    background: #ccfbf1;
}

.action-view:hover {
    background: #dbeafe;
}

.action-delete:hover {
    background: #fee2e2;
}

small {
    color: var(--muted);
}

@media (max-width: 900px) {
    .topbar {
        padding: 16px;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .nav {
        align-items: stretch;
        padding: 10px 14px;
    }

    .nav-dropdown {
        width: 100%;
    }

    .nav-dropdown-trigger {
        width: 100%;
        justify-content: space-between;
    }

    .nav-dropdown-menu {
        position: static;
        display: none;
        min-width: 0;
        width: 100%;
        margin-top: 6px;
        box-shadow: none;
    }

    .nav-dropdown.open .nav-dropdown-menu,
    .nav-dropdown:focus-within .nav-dropdown-menu {
        display: flex;
    }

    .two-col {
        grid-template-columns: 1fr;
    }

    .inline-pair {
        grid-template-columns: 1fr;
    }

    .form-grid,
    .form-grid.compact {
        grid-template-columns: 1fr;
    }

    .container {
        width: calc(100% - 20px);
        margin-top: 12px;
        gap: 12px;
    }

    .card {
        padding: 14px;
    }

    table {
        min-width: 720px;
    }

    table.sticky-cols-2 {
        --sticky-col-1-width: 96px;
        --sticky-col-2-width: 170px;
    }

    .filter-form-row {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        width: 100%;
        justify-content: flex-start;
    }
}
