:root {
    --brand-bg: #f0f0f0;
    --brand-bg-deep: #e8e8e8;
    --surface: #ffffff;
    --surface-soft: #f7f7f7;
    --border: #d4d4d4;
    --text: #000000;
    --text-body: #333333;
    --text-muted: #777777;
    --accent: #4c9ff3;
    --accent-strong: #2376cc;
    --accent-soft: #e7f1fc;
    --danger: #a12b2b;
    --danger-strong: #7f2020;
    --success-bg: #eaf5ea;
    --success-border: #b6d7b8;
    --success-text: #245c2d;
    --shadow-soft: 0 18px 36px rgba(0, 0, 0, 0.08);
    --shadow-hard: 0 24px 55px rgba(0, 0, 0, 0.22);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 300;
    color: var(--text-body);
    background:
        radial-gradient(circle at 16% 0%, #ffffff 0%, rgba(255, 255, 255, 0) 36%),
        linear-gradient(165deg, #f6f6f6 0%, var(--brand-bg) 58%, var(--brand-bg-deep) 100%);
    min-width: 320px;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: linear-gradient(transparent 97%, rgba(0, 0, 0, 0.025) 100%);
    background-size: 100% 36px;
    opacity: 0.18;
}

.app-shell {
    position: relative;
    z-index: 1;
    max-width: 1560px;
    margin: 0 auto;
    padding: 22px 24px 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    padding: 18px 22px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-radius: 6px;
    box-shadow: var(--shadow-soft);
}

.brand-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 260px;
}

.brand-wordmark {
    display: inline-block;
    color: var(--text);
    font-size: 2rem;
    line-height: 1;
    font-weight: 500;
    letter-spacing: 0.01em;
    text-decoration: none;
    text-transform: lowercase;
}

.brand-wordmark:hover {
    color: var(--accent);
}

.brand-subline {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.74rem;
    letter-spacing: 0.36em;
    text-transform: uppercase;
}

.topbar-meta {
    text-align: right;
}

.topbar-meta h1 {
    margin: 0;
    color: var(--text);
    font-size: 1.34rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.topbar-meta p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}

.topbar-tools {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.topbar-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 1px solid #c6c6c6;
    border-radius: 4px;
    background: var(--surface-soft);
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.topbar-link:hover {
    background: #ececec;
}

.alert {
    border-radius: 4px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.95rem;
    border: 1px solid transparent;
}

.alert-error {
    color: #6f1d1d;
    background: #f8e9e9;
    border-color: #e6c1c1;
}

.alert-success {
    color: var(--success-text);
    background: var(--success-bg);
    border-color: var(--success-border);
}

.alert-subtle {
    margin-top: 6px;
    color: #2f5a40;
    font-size: 0.86rem;
}

.layout-grid {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 152px);
}

.panel {
    background: var(--surface);
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    box-shadow: var(--shadow-soft);
}

.panel-left {
    padding: 16px;
}

.panel-right {
    padding: 18px;
    overflow: hidden;
}

.panel-header {
    margin-bottom: 12px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
}

.panel-header p {
    margin: 5px 0 0;
    color: var(--text-muted);
}

.panel-header-spread {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: start;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: end;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.inline-form-stack {
    display: block;
    margin-bottom: 16px;
}

.inline-form-stack label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.inline-form-row {
    display: flex;
    gap: 8px;
}

input,
select,
button,
a.btn {
    font: inherit;
}

input,
select {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    background: #fff;
    color: var(--text-body);
}

input:focus,
select:focus {
    outline: 2px solid rgba(76, 159, 243, 0.23);
    border-color: var(--accent);
}

.btn {
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 8px 12px;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    font-size: 0.9rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-weight: 500;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.btn-small {
    padding: 6px 9px;
    font-size: 0.78rem;
}

.btn-icon {
    width: 34px;
    min-width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1.2rem;
    line-height: 1;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.btn-secondary {
    background: var(--surface-soft);
    color: var(--text);
    border-color: #c6c6c6;
}

.btn-secondary:hover {
    background: #ececec;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-strong);
    border-color: var(--danger-strong);
}

.list-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-group {
    border: 1px solid #d8d8d8;
    border-radius: 4px;
    background: #fff;
    overflow: hidden;
}

.list-group > summary {
    list-style: none;
}

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

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    color: var(--text);
    padding: 10px 12px;
    border: 0;
    font-weight: 400;
    cursor: pointer;
    user-select: none;
}

.list-item-main {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.list-item-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.list-group > .list-item::after {
    content: "+";
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    margin-left: 10px;
}

.list-group[open] > .list-item::after {
    content: "-";
}

.list-item:hover {
    background: var(--surface-soft);
}

.list-group.active > .list-item {
    background: var(--accent-soft);
    border-color: #c6dcf5;
    font-weight: 500;
}

.list-item-count {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.list-item-add {
    width: 22px;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid #c8c8c8;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    font-weight: 500;
}

.list-item-add:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.list-group-body {
    border-top: 1px solid #ececec;
    background: #fcfcfc;
    padding: 10px;
}

.list-group-open {
    width: 100%;
    margin-bottom: 8px;
}

.group-contact-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.group-contact-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    border: 1px solid #e7e7e7;
    border-radius: 4px;
    background: #fff;
}

.group-contact-name {
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.group-contact-name:hover {
    color: var(--accent);
}

.group-contact-phone {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.data-grid-wrap {
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 14px;
    background: #fff;
}

.data-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.data-grid th,
.data-grid td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e2e2;
    vertical-align: middle;
}

.data-grid th {
    background: #f4f4f4;
    font-size: 0.84rem;
    color: #515151;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 500;
}

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

.data-grid td:last-child {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.editor-card {
    border: 1px solid rgba(0, 0, 0, 0.16);
    border-radius: 6px;
    padding: 12px;
    background: #fafafa;
}

.editor-card h3 {
    margin: 0 0 10px;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text);
}

.editor-form {
    display: grid;
    gap: 7px;
    max-width: 620px;
}

.editor-form label {
    color: var(--text-muted);
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.import-card {
    margin-bottom: 14px;
}

.inline-hidden {
    display: none;
}

.empty-note {
    color: var(--text-muted);
    margin: 8px 0;
}

.panel-empty {
    display: grid;
    place-content: center;
    min-height: 300px;
    color: var(--text-muted);
    text-align: center;
}

.danger-note {
    margin: 0;
    font-size: 0.86rem;
    color: #852020;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 20, 0.47);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 40;
}

.modal.visible {
    display: flex;
}

.modal-card {
    width: min(430px, calc(100vw - 30px));
    background: #fff;
    border: 1px solid #c9c9c9;
    border-radius: 6px;
    padding: 16px;
    box-shadow: var(--shadow-hard);
}

.import-modal-card {
    width: min(620px, calc(100vw - 30px));
}

.import-modal-card .editor-form {
    max-width: 100%;
}

.modal-card h2 {
    margin-top: 0;
    font-size: 1.08rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text);
}

.modal-actions {
    margin-top: 14px;
    display: flex;
    gap: 10px;
    justify-content: end;
    flex-wrap: wrap;
}

@media (max-width: 1100px) {
    .app-shell {
        padding: 16px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-meta {
        text-align: left;
    }

    .topbar-tools {
        justify-content: flex-start;
    }

    .layout-grid {
        grid-template-columns: 1fr;
        min-height: unset;
    }

    .panel-left {
        order: 1;
    }

    .panel-right {
        order: 2;
    }

    .panel-header-spread {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 680px) {
    body {
        font-size: 15px;
    }

    .brand-wordmark {
        font-size: 1.62rem;
    }

    .topbar-meta h1 {
        font-size: 1.08rem;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .btn.btn-icon {
        width: 34px;
        justify-self: start;
    }

    .topbar-tools {
        width: 100%;
    }

    .topbar-link {
        width: 100%;
    }

    .header-actions,
    .inline-form-row,
    .editor-actions {
        width: 100%;
    }

    .inline-form,
    .inline-form-row {
        display: grid;
        grid-template-columns: 1fr;
    }

    .data-grid td:last-child {
        display: grid;
        grid-template-columns: 1fr;
    }
}
