:root {
    color-scheme: light;
    --bg: #edf1ee;
    --surface: #ffffff;
    --surface-2: #f6f8f7;
    --ink: #19211d;
    --muted: #66736c;
    --line: #cfd8d2;
    --accent: #1f7a55;
    --accent-strong: #155e42;
    --danger: #b4232b;
    --paper: #fbfbfa;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea,
a.button {
    font: inherit;
}

button,
a.button {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
}

button {
    padding: 0 14px;
}

button:disabled {
    cursor: not-allowed;
    opacity: .52;
}

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

.ghost {
    background: transparent;
}

a.button {
    display: inline-grid;
    place-items: center;
    padding: 0 14px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 66px;
    padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
    background: rgba(237, 241, 238, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand,
.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand div,
.login-brand div {
    display: grid;
    gap: 2px;
}

.brand span,
.login-brand p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.app-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: #c0262d;
    color: white;
    font-size: 13px;
    font-weight: 800;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-layout {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 84px;
    min-height: calc(100vh - 66px);
}

.file-panel {
    position: sticky;
    top: 66px;
    height: calc(100vh - 66px);
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 14px;
    background: var(--surface-2);
    border-right: 1px solid var(--line);
    overflow: auto;
}

.panel-section {
    display: grid;
    gap: 10px;
}

.panel-section h2 {
    margin: 4px 0 0;
    font-size: 15px;
}

.pathbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.pathbar span {
    overflow: hidden;
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-list,
.history-list {
    display: grid;
    gap: 6px;
}

.file-row,
.history-row,
.muted-row {
    width: 100%;
    min-height: 52px;
    text-align: left;
}

.file-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 10px;
    padding: 8px 10px;
}

.file-icon {
    grid-row: 1 / 3;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #e4ece7;
    color: var(--accent-strong);
    font-size: 11px;
    font-weight: 800;
}

.file-row.file .file-icon {
    background: #f3d8da;
    color: #a31e25;
}

.file-name,
.file-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-name {
    font-weight: 700;
}

.file-meta {
    color: var(--muted);
    font-size: 12px;
}

.history-row,
.muted-row {
    padding: 10px 12px;
}

.muted-row {
    color: var(--muted);
}

.workspace {
    position: relative;
    min-width: 0;
    padding: 18px 14px 86px;
    overflow: hidden;
}

.empty-state {
    max-width: 680px;
    margin: 15vh auto 0;
    color: var(--muted);
    text-align: center;
}

.empty-state h1 {
    margin: 0 0 10px;
    color: var(--ink);
    font-size: 34px;
    line-height: 1.15;
}

.empty-state p {
    margin: 0;
    font-size: 17px;
    line-height: 1.5;
}

.loading-state {
    position: fixed;
    left: 50%;
    top: 82px;
    z-index: 50;
    transform: translateX(-50%);
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 28px rgba(20, 35, 28, .18);
}

.pdf-viewer {
    display: grid;
    justify-items: center;
    gap: 18px;
    width: 100%;
}

.page {
    position: relative;
    width: min(100%, var(--page-width));
    aspect-ratio: var(--page-ratio);
    background: var(--paper);
    box-shadow: 0 10px 30px rgba(20, 35, 28, .25);
    touch-action: none;
}

.page canvas,
.annotation-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.annotation-layer {
    z-index: 2;
}

.text-note {
    position: absolute;
    z-index: 3;
    min-width: 120px;
    min-height: 38px;
    max-width: min(320px, 55%);
    padding: 6px 8px;
    border: 2px solid rgba(31, 122, 85, .7);
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    color: #111827;
    font-size: 18px;
    outline: none;
    resize: both;
    touch-action: manipulation;
}

.text-note::placeholder {
    color: #8a948e;
}

.toast-region {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 50%;
    z-index: 100;
    display: grid;
    gap: 8px;
    width: min(92vw, 440px);
    pointer-events: none;
    transform: translateX(-50%);
}

.toast {
    padding: 12px 14px;
    border: 1px solid #bcd4c7;
    border-radius: 8px;
    background: #effaf4;
    color: #155e42;
    box-shadow: 0 12px 30px rgba(20, 35, 28, .18);
    font-weight: 700;
    opacity: 1;
    transform: translateY(0);
    transition: opacity .22s ease, transform .22s ease;
}

.toast.error {
    border-color: #ef9aa0;
    background: #fff1f2;
    color: var(--danger);
}

.toast.leaving {
    opacity: 0;
    transform: translateY(-12px);
}

.toolbox {
    position: sticky;
    top: 66px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: calc(100vh - 66px);
    padding: 12px 10px;
    background: var(--surface-2);
    border-left: 1px solid var(--line);
}

.toolbox button,
.control {
    width: 64px;
}

.toolbox button {
    height: 52px;
    padding: 0;
    font-size: 14px;
    font-weight: 700;
}

.toolbox button.active {
    border-color: var(--accent);
    background: #dcebe4;
    color: var(--accent-strong);
}

.control {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.control input[type="color"] {
    width: 64px;
    height: 44px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.control input[type="range"] {
    width: 64px;
    accent-color: var(--accent);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
}

.login-shell {
    width: min(100%, 430px);
}

.login-panel {
    display: grid;
    gap: 16px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 16px 38px rgba(20, 35, 28, .15);
}

.login-panel h1 {
    margin: 0;
    font-size: 25px;
}

.login-panel label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

.login-panel input {
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    color: var(--ink);
    background: var(--surface-2);
}

.notice {
    padding: 11px 12px;
    border: 1px solid #ef9aa0;
    border-radius: 8px;
    background: #fff1f2;
    color: var(--danger);
}

@media (max-width: 960px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .top-actions {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .top-actions button,
    .top-actions .button {
        padding-inline: 8px;
    }

    .app-layout {
        grid-template-columns: 1fr;
        padding-bottom: 78px;
    }

    .file-panel {
        position: fixed;
        inset: 0 0 78px 0;
        z-index: 40;
        display: none;
        height: auto;
        padding-top: 86px;
        border-right: 0;
    }

    .file-panel.open {
        display: flex;
    }

    .workspace {
        padding: 12px 8px 92px;
    }

    .toolbox {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        flex-direction: row;
        align-items: center;
        height: 78px;
        padding: 8px max(10px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-right));
        border-top: 1px solid var(--line);
        border-left: 0;
        overflow-x: auto;
    }

    .empty-state {
        margin-top: 10vh;
        padding: 0 10px;
    }

    .empty-state h1 {
        font-size: 28px;
    }
}
