:root {
    --bg: #fafaf7;
    --panel: #ffffff;
    --border: #e4e2db;
    --text: #1a1a1a;
    --muted: #6b6b6b;
    --accent: #2f6f4e;
    --accent-dark: #245a3f;
    --accent-soft: #e8f1ec;
    --warn: #c0392b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
    color-scheme: light;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- header ---------- */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 22px 24px 0;
}

.site-header .title-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
}

.brand:hover {
    text-decoration: none;
}

.site-header .sub {
    color: var(--muted);
    font-size: 13px;
}

nav {
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 13px;
}

nav form {
    margin: 0;
}

nav .who {
    color: var(--muted);
}

nav button {
    border: 0;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    padding: 0;
}

nav button:hover {
    text-decoration: underline;
}

main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 24px 80px;
}

/* ---------- layout ---------- */
.grid {
    display: grid;
    grid-template-columns: 260px 380px 1fr;
    grid-template-areas: "sidebar inputs results";
    gap: 20px;
    align-items: start;
}

.sidebar {
    grid-area: sidebar;
    position: sticky;
    top: 16px;
}

.inputs-col {
    grid-area: inputs;
}

.results-col {
    grid-area: results;
}

@media (max-width: 1100px) {
    .grid {
        grid-template-columns: 380px 1fr;
        grid-template-areas:
            "sidebar sidebar"
            "inputs  results";
    }

    .sidebar {
        position: static;
    }
}

@media (max-width: 720px) {
    .grid {
        grid-template-columns: 1fr;
        grid-template-areas: "sidebar" "inputs" "results";
    }

    .site-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

/* ---------- panels ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.panel + .panel {
    margin-top: 20px;
}

.panel h2 {
    margin: 0 0 16px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-title h2 {
    margin: 0;
}

.section-title .note {
    font-size: 11px;
    color: var(--muted);
}

/* ---------- form fields ---------- */
.dcf-form {
    margin: 0;
}

.field {
    margin-bottom: 14px;
}

.field:last-child {
    margin-bottom: 0;
}

.field label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.field label .hint {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #eceae3;
    color: #999;
    font-size: 10px;
    font-weight: 700;
    cursor: help;
}

.field input,
.field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font: inherit;
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}

.field input:focus,
.field select:focus {
    border-color: var(--accent);
}

.field.has-error input,
.field.has-error select {
    border-color: var(--warn);
}

.suffix-wrap {
    position: relative;
}

.suffix-wrap input {
    padding-right: 32px;
}

.suffix-wrap .suffix {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--muted);
    pointer-events: none;
}

.row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.footnote {
    color: var(--muted);
    font-size: 12px;
    margin-top: 14px;
    line-height: 1.6;
}

.footnote ul {
    padding-left: 18px;
    margin: 4px 0;
}

/* ---------- buttons ---------- */
.btn-primary {
    padding: 9px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}

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

.btn-primary:disabled {
    background: #b8b8b8;
    cursor: not-allowed;
}

.btn-primary.full {
    width: 100%;
    margin-top: 4px;
}

/* ---------- results / stats ---------- */
.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.stat {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    background: #fff;
}

.stat .k {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .04em;
    text-transform: uppercase;
}

.stat .v {
    font-size: 20px;
    font-weight: 600;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.stat.highlight {
    background: var(--accent-soft);
    border-color: #c8ddd1;
}

.stat.highlight .v {
    color: var(--accent);
}

@media (max-width: 720px) {
    .summary {
        grid-template-columns: 1fr 1fr;
    }
}

/* ---------- tables ---------- */
table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th,
td {
    padding: 8px 10px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

th:first-child,
td:first-child {
    text-align: left;
}

th {
    font-weight: 500;
    color: var(--muted);
    background: #faf8f3;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #fafaf5;
}

tfoot td {
    font-weight: 600;
    background: #faf8f3;
    border-top: 2px solid var(--border);
    border-bottom: none;
}

.sens-table th,
.sens-table td {
    text-align: center;
    padding: 8px 6px;
}

.sens-table th {
    background: #faf8f3;
}

.sens-table td.label {
    font-weight: 600;
    background: #faf8f3;
    color: var(--muted);
}

.sens-table td.center-cell {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    font-weight: 600;
}

/* ---------- warnings / notices ---------- */
.warn {
    background: #fdf2f0;
    border: 1px solid #f1c8c1;
    color: var(--warn);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 12px;
    display: none;
}

.warn.show {
    display: block;
}

.notice {
    color: #8a6d1b;
    background: #fcf7e8;
    border: 1px solid #ecdca8;
    border-radius: 6px;
    padding: 9px 11px;
    font-size: 13px;
    margin: 0 0 14px;
}

.error {
    color: var(--warn);
    font-size: 12px;
    margin-top: 4px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

/* ---------- messages ---------- */
.messages {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
}

.message {
    padding: 10px 14px;
    border: 1px solid #c8ddd1;
    border-radius: 8px;
    color: var(--accent-dark);
    background: var(--accent-soft);
    font-size: 13px;
}

.message.error {
    border-color: #f1c8c1;
    color: var(--warn);
    background: #fdf2f0;
}

/* ---------- sidebar: tags ---------- */
.sidebar-section + .sidebar-section {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.save-row {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.save-row input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font: inherit;
    outline: none;
}

.save-row input:focus {
    border-color: var(--accent);
}

.tag-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.tag-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 6px 7px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
}

.tag-list .tag-name {
    font-weight: 500;
}

.tag-count {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: #eceae3;
    color: var(--muted);
    font-style: normal;
    font-size: 11px;
    font-weight: 600;
}

.tag-list form {
    margin: 0;
    display: flex;
}

.icon-del {
    background: none;
    border: none;
    color: #b8b8b8;
    padding: 0 8px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: color .15s;
}

.icon-del:hover {
    color: var(--warn);
}

/* ---------- sidebar: favorites ---------- */
.tag-group {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    margin-bottom: 8px;
}

.tag-group summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    background: #faf8f3;
    list-style: none;
}

.tag-group summary::-webkit-details-marker {
    display: none;
}

.tag-group summary em {
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 999px;
    color: #fff;
    background: var(--accent);
    font-style: normal;
    font-size: 11px;
    text-align: center;
}

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

.fav-item {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    transition: border-color .15s, background .15s;
}

.fav-item:hover {
    border-color: #c8c5b8;
    background: #faf8f3;
}

.fav-item.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.fav-load {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: none;
    border: none;
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.fav-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fav-item.active .fav-name {
    color: var(--accent);
}

.fav-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fav-del {
    background: none;
    border: none;
    color: #b8b8b8;
    padding: 0 10px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: color .15s;
}

.fav-del:hover {
    color: var(--warn);
}

.fav-empty {
    text-align: center;
    padding: 20px 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
}

/* ---------- auth pages ---------- */
.auth-card {
    max-width: 420px;
    margin: 48px auto;
}

.auth-card h1 {
    margin: 0 0 18px;
    font-size: 20px;
    font-weight: 600;
}

.auth-card p label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.auth-card input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font: inherit;
    outline: none;
}

.auth-card input:focus {
    border-color: var(--accent);
}

.auth-card ul {
    color: var(--muted);
    font-size: 12px;
    padding-left: 18px;
    margin: 4px 0 0;
}

.auth-card .helptext {
    color: var(--muted);
    font-size: 11px;
}
