:root {
    --page-bg: #ece7e1;
    --panel-bg: rgba(255, 255, 255, 0.68);
    --panel-strong: #f5f1ed;
    --panel-muted: #e8e2dc;
    --border: #d7d0c7;
    --text: #2f2d2a;
    --muted: #625d5a;
    --shadow: 0 10px 30px rgba(34, 30, 27, 0.08);
    --accent: #8a7967;
    --accent-strong: #665b51;
    --accent-soft: rgba(138, 121, 103, 0.12);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #f3efe9 0%, var(--page-bg) 100%);
    color: var(--text);
}

body {
    min-height: 100vh;
    padding: 22px;
    position: relative;
}

main {
    width: 100%;
    height: calc(100vh - 44px);
    height: calc(100dvh - 44px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(0, 4fr) minmax(180px, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas:
        "header header header"
        "nav nav nav"
        "side-left body side-right";
    gap: 14px;
    position: relative;
    z-index: 1;
}

.main-box {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    padding: 16px 18px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(4px);
}

#main-head {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    background: linear-gradient(135deg, rgba(255,255,255,0.7), var(--panel-muted));
    border-color: rgba(138, 121, 103, 0.25);
    position: relative;
    overflow: hidden;
}

#main-head::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 6px;
    background: linear-gradient(180deg, var(--accent), transparent);
}

#header-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent-soft);
    border: 1px solid rgba(138, 121, 103, 0.2);
}

#header-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.icon-small img {
    display: block;
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.header-content {
    color: inherit;
    text-decoration: none;
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
}

.brand-version {
    align-self: flex-start;
    margin: 2px 0 0 -4px;
    padding-left: 10px;
    border-left: 1px solid var(--accent);
    color: var(--accent-strong);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.2;
}

.header-content:hover .brand-name {
    color: var(--accent-strong);
}

.header-content:focus-visible {
    border-radius: 8px;
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

#navigation {
    grid-area: nav;
    display: flex;
    align-items: center;
    min-height: 64px;
    background: linear-gradient(180deg, var(--panel-bg), rgba(255,255,255,0.55));
}

.button-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.35);
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.toolbar-row,
.toolbar-actions,
.search-form {
    display: inline-flex;
    align-items: center;
}

.toolbar-row {
    width: 100%;
    gap: 10px;
}

.toolbar-actions {
    gap: 8px;
    margin-left: auto;
}

.toolbar-button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(255,255,255,0.55);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.16s ease, border-color 0.16s ease;
}

.toolbar-button:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.toolbar-button:focus-visible,
.search-field:focus-within,
.dialog-close:focus-visible,
.dialog-links a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.switcher-button {
    flex: 0 0 auto;
}

.toolbar-button kbd {
    padding: 2px 5px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    font: 0.72rem ui-monospace, SFMono-Regular, Consolas, monospace;
}

.search-form {
    flex: 1 1 190px;
    min-width: 120px;
    gap: 6px;
}

.search-field {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(255,255,255,0.55);
    color: var(--muted);
}

.search-field > span {
    font-size: 1.25rem;
    line-height: 1;
}

.search-field input {
    width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
}

.search-field input::placeholder {
    color: var(--muted);
}

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

.primary-action:hover {
    background: var(--text);
    border-color: var(--text);
}

.toolbar-status {
    min-height: 0;
    margin: 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.toolbar-status:not(:empty) {
    margin: 5px 0 0 2px;
}

.toolbar-dialog {
    width: min(440px, calc(100vw - 32px));
    max-height: min(80vh, 620px);
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-strong);
    color: var(--text);
    box-shadow: 0 24px 70px rgba(34, 30, 27, 0.24);
}

.toolbar-dialog::backdrop {
    background: rgba(35, 31, 28, 0.36);
    backdrop-filter: blur(2px);
}

.dialog-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dialog-heading h2 {
    margin: 0;
    font-size: 1.1rem;
}

.dialog-close {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 1.25rem;
    cursor: pointer;
}

.dialog-hint {
    margin: 12px 0;
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.45;
}

.empty-state {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.45);
}

.empty-state-title {
    margin: 0;
    font-size: 0.96rem;
    font-weight: 650;
}

.empty-state .dialog-hint {
    margin: 6px 0 14px;
}

.empty-state a,
.settings-action {
    text-decoration: none;
}

.connection-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.connection-state::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9b6559;
}

.integration-label {
    margin: 16px 0 6px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.integration-list {
    display: flex;
    gap: 8px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.integration-list li {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: rgba(255,255,255,0.45);
    font-size: 0.84rem;
}

.settings-action {
    width: 100%;
}

.empty-state a:hover,
.settings-action:hover {
    background: var(--text);
    border-color: var(--text);
}

.activity-list {
    display: grid;
    gap: 8px;
    max-height: 55vh;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    overflow: auto;
}

.activity-item {
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.56);
}

.activity-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.activity-type,
.activity-heading time,
.empty-activity {
    color: var(--muted);
    font-size: 0.78rem;
}

.activity-description {
    margin: 6px 0 10px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.undo-button {
    appearance: none;
    min-height: 32px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.undo-button:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.undo-button:disabled {
    color: var(--muted);
    cursor: default;
}

.empty-activity {
    margin: 0;
    padding: 14px 0;
}

.toolbar-dialog [role="feed"] {
    scroll-behavior: smooth;
}

.dialog-close:hover {
    background: var(--accent-soft);
}

.dialog-close:focus-visible,
.toolbar-dialog input:focus-visible,
.toolbar-dialog textarea:focus-visible,
.toolbar-dialog select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

#sidebar-left {
    grid-area: side-left;
    background: linear-gradient(180deg, rgba(245,241,237,0.95), rgba(232,226,220,0.85));
}

#sidebar-left ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

#sidebar-left li {
    margin: 0;
}

.button-sidebar {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--text);
    background: transparent;
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    text-decoration: none;
}

.button-sidebar:hover {
    background: var(--accent-soft);
    border-color: rgba(138, 121, 103, 0.2);
    transform: translateX(2px);
}

#body {
    grid-area: body;
    min-height: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.72), rgba(245,241,237,0.85));
    padding: 0;
    overflow: hidden;
}

#body iframe {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
}

#sidebar-right {
    grid-area: side-right;
    background: linear-gradient(180deg, rgba(245,241,237,0.95), rgba(232,226,220,0.9));
    color: var(--muted);
    font-weight: 500;
}

.mobile-controls {
    display: none;
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-toggle {
    appearance: none;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.7);
    color: var(--text);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: var(--shadow);
}

@media (min-width: 901px) {
    .mobile-controls {
        display: none !important;
    }
}

@media (max-width: 900px) {
    body {
        padding: 16px;
    }

    #main-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding-right: 12px;
    }

    #navigation {
        padding: 10px;
    }

    .toolbar-row {
        flex-wrap: wrap;
    }

    .search-form {
        order: 3;
        flex: 1 1 100%;
    }

    .mobile-controls {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-left: auto;
    }

    main {
        height: calc(100vh - 32px);
        height: calc(100dvh - 32px);
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "nav"
            "body";
        gap: 12px;
        padding-top: 6px;
    }

    #sidebar-left,
    #sidebar-right {
        position: fixed;
        top: 220px;
        bottom: 16px;
        width: min(280px, 76vw);
        z-index: 15;
        transition: transform 0.25s ease;
        box-shadow: 0 16px 32px rgba(34, 30, 27, 0.14);
    }

    #sidebar-left {
        left: 16px;
        transform: translateX(-120%);
    }

    #sidebar-right {
        right: 16px;
        transform: translateX(120%);
    }

    body.sidebar-left-open #sidebar-left {
        transform: translateX(0);
    }

    body.sidebar-right-open #sidebar-right {
        transform: translateX(0);
    }

    #body {
        min-height: 220px;
    }
}

@media (max-width: 520px) {
    .toolbar-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .switcher-button {
        justify-self: start;
    }

    .toolbar-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        width: 100%;
        margin-left: 0;
        gap: 6px;
    }

    .toolbar-button {
        min-height: 38px;
        padding: 7px 4px;
        font-size: 0.8rem;
    }

    .toolbar-actions .toolbar-button {
        width: 100%;
    }

    .switcher-button kbd {
        display: none;
    }

    .search-form {
        width: 100%;
        min-width: 0;
    }

    #sidebar-left,
    #sidebar-right {
        top: 274px;
    }
}

