:root {
    --bg: #1b1d21;
    --panel: #24272d;
    --panel-2: #2d3138;
    --line: #3a3f47;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --accent: #4c9cff;
    --ok: #3fb950;
    --warn: #d29922;
    --bad: #f85149;
    --term-bg: #121316;
    --app-h: 100dvh;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    -webkit-text-size-adjust: 100%;
}

body {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--app-h);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

[hidden] { display: none !important; }

button {
    font: inherit;
    color: inherit;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 12px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
button:active { background: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

#bar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 4px 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
#title-box { flex: 1; min-width: 0; }
#title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle:empty { display: none; }
.icon { background: none; border: none; font-size: 22px; line-height: 1; padding: 6px 8px; }
.icon.small { font-size: 14px; padding: 6px; }
#term-tools { display: flex; gap: 2px; }

.dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--ok); }
.dot.connecting, .dot.pending { background: var(--warn); }
.dot.offline, .dot.error { background: var(--bad); }

#notice {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    background: #3a2f12;
    color: #f2d58a;
}
#notice.error { background: #3d1d1d; color: #ffb3ad; }
#notice-text { flex: 1; }
#notice-action { padding: 3px 10px; font-size: 13px; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#list-view, #setup-view { overflow-y: auto; -webkit-overflow-scrolling: touch; }

#tabs { list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.tab {
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
}
.tab:active { background: var(--panel-2); }
.tab.active { border-color: var(--accent); }
.tab .row { display: flex; align-items: center; gap: 8px; }
.tab .kind {
    flex: none;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--panel-2);
    color: var(--muted);
}
.tab .kind.ssh { color: #8cc8ff; }
.tab .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab .age { flex: none; font-size: 12px; color: var(--muted); }
.tab .preview {
    margin-top: 4px;
    font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tab .preview:empty { display: none; }
.tab.closed .name { color: var(--muted); }
.tab .state { font-size: 11px; color: var(--bad); }

.hint { color: var(--muted); font-size: 13px; padding: 0 16px; }
.error { color: var(--bad); font-size: 13px; padding: 0 16px; }

#setup-view { padding: 8px 0 24px; }
#setup-view h2 { font-size: 18px; margin: 12px 16px; }
#setup-view ol { margin: 0 16px 12px; padding-left: 20px; }
#setup-view li { margin: 4px 0; }
#link-input {
    display: block;
    width: calc(100% - 32px);
    margin: 0 16px 10px;
    padding: 8px;
    font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}
#link-btn { margin: 0 16px; }

#term-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: var(--term-bg);
    -webkit-overflow-scrolling: touch;
}
#term { display: inline-block; padding: 2px; min-width: 100%; }
#term .xterm { padding: 0; }

#input-area {
    flex: none;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
#keys {
    display: flex;
    gap: 6px;
    padding: 6px 8px;
    overflow-x: auto;
    scrollbar-width: none;
}
#keys::-webkit-scrollbar { display: none; }
#keys button {
    flex: none;
    min-width: 42px;
    padding: 6px 8px;
    font: 13px ui-monospace, Menlo, Consolas, monospace;
}
#input-form { display: flex; align-items: flex-end; gap: 6px; padding: 0 8px 8px; }
#input {
    flex: 1;
    min-width: 0;
    max-height: 120px;
    resize: none;
    padding: 8px 10px;
    font: 15px/1.4 ui-monospace, Menlo, Consolas, monospace;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
}
#enter-toggle {
    flex: none;
    display: flex;
    align-items: center;
    gap: 3px;
    padding-bottom: 9px;
    font-size: 13px;
    color: var(--muted);
}
#send { flex: none; background: var(--accent); border-color: var(--accent); color: #fff; padding: 8px 14px; }
#readonly { padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); }

#sheet {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-end;
    background: rgba(0, 0, 0, .45);
}
#sheet-panel {
    width: 100%;
    max-height: 80%;
    overflow-y: auto;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-radius: 14px 14px 0 0;
}
#sheet-items { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
#sheet-items .label { font-size: 12px; color: var(--muted); padding: 6px 4px 0; }
#sheet-items button, #sheet-close { width: 100%; text-align: left; padding: 11px 12px; }
#sheet-items button.current { border-color: var(--accent); }
#sheet-items button.danger { color: var(--bad); }
#sheet-close { text-align: center; }

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(96px + env(safe-area-inset-bottom));
    z-index: 30;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 8px 14px;
    font-size: 13px;
    background: rgba(40, 43, 49, .96);
    border: 1px solid var(--line);
    border-radius: 18px;
}
