:root {
    --bg: #f2f2f7;
    --surface: #ffffff;
    --surface-2: #f9f9fb;
    --primary: #007aff;
    --primary-dark: #0062cc;
    --danger: #ff3b30;
    --danger-dark: #cc2f26;
    --text: #1c1c1e;
    --text-2: #8e8e93;
    --text-3: #c7c7cc;
    --border: rgba(60,60,67,0.1);
    --border-2: rgba(60,60,67,0.18);
    --user-bubble: #007aff;
    --bot-bubble: #e5e5ea;
    --r: 20px;
    --r-sm: 12px;
    --shadow: 0 4px 32px rgba(0,0,0,0.07);
    --shadow-sm: 0 1px 6px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.app {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 680px;
    height: calc(100dvh - 32px);
    max-height: 900px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── Header ─── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.2px;
}

.app-logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, #007aff 0%, #5ac8fa 100%);
    flex-shrink: 0;
}

.header-actions { display: flex; gap: 2px; }

.icon-btn {
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: var(--text-2);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ─── Settings Panel ─── */
.settings-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4,0,0.2,1);
    flex-shrink: 0;
    border-bottom: 1px solid transparent;
}
.settings-panel.open {
    max-height: 700px;
    border-bottom-color: var(--border);
}

.settings-content {
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--surface-2);
    overflow-y: auto;
    max-height: 620px;
}

.settings-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    letter-spacing: 0.2px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

input, textarea, select {
    font-family: inherit;
    font-size: 14px;
    padding: 9px 12px;
    border: 1.5px solid var(--border-2);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text);
    width: 100%;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}
textarea {
    resize: vertical;
    min-height: 88px;
    line-height: 1.5;
    font-size: 13px;
}
small, .status-hint {
    font-size: 12px;
    color: var(--text-3);
}
.status-hint { font-size: 11px; }

.input-row {
    display: flex;
    gap: 8px;
}
.input-row input { flex: 1; }

.btn-load {
    padding: 9px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.15s;
    flex-shrink: 0;
}
.btn-load:hover { background: var(--primary-dark); }
.btn-load:disabled { opacity: 0.5; cursor: not-allowed; }

.segmented {
    display: flex;
    background: var(--bg);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
}
.seg-btn {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: transparent;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.seg-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    letter-spacing: normal;
    text-transform: none;
}

/* ─── Chat ─── */
.chat-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}
.chat-log::-webkit-scrollbar { width: 3px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

.message {
    max-width: 72%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}
.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.bot {
    align-self: flex-start;
    background: var(--bot-bubble);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-3);
    font-size: 12px;
    text-align: center;
    max-width: 90%;
    padding: 2px 0;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
    background: var(--bot-bubble);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-3);
    border-radius: 50%;
    animation: dot-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
    0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ─── Status Section ─── */
.status-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.status-orb {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.orb-core {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text-3);
    transition: background 0.3s ease;
}

.status-orb.listening .orb-core  { background: var(--primary); animation: orb-pulse 1.4s ease-in-out infinite; }
.status-orb.thinking .orb-core   { background: #ff9500; animation: orb-pulse 0.7s ease-in-out infinite; }
.status-orb.speaking .orb-core   { background: #34c759; animation: orb-pulse 1.8s ease-in-out infinite; }
.status-orb.recording .orb-core  { background: var(--danger); animation: orb-pulse 0.55s ease-in-out infinite; }

@keyframes orb-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.18); opacity: 0.75; }
}

.status-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
}

.session-btns { display: flex; gap: 8px; }

.btn-primary, .btn-danger {
    padding: 9px 24px;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: var(--danger-dark); }

/* ─── Input Area ─── */
.input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.input-area input {
    flex: 1;
    border-radius: 999px;
    padding: 10px 16px;
    background: var(--bg);
    border: none;
    font-size: 15px;
}
.input-area input:focus {
    outline: none;
    box-shadow: none;
    border: none;
}

.round-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.send-btn { background: var(--primary); color: #fff; }
.send-btn:hover { background: var(--primary-dark); transform: scale(1.05); }

.mic-btn { background: var(--bg); color: var(--text-2); }
.mic-btn:hover { background: var(--border-2); color: var(--text); }
.mic-btn.recording { background: var(--danger); color: #fff; animation: orb-pulse 0.55s ease-in-out infinite; }

/* ─── Input mode tabs ─── */
.input-mode-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 14px 0;
    flex-shrink: 0;
}
.mode-tab {
    flex: 1;
    padding: 7px 12px;
    border: 1.5px solid var(--border-2);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.mode-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ─── Dictaphone area ─── */
.dict-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.record-main-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    box-shadow: 0 4px 16px rgba(0,122,255,0.3);
}
.record-main-btn:hover { transform: scale(1.05); }
.record-main-btn.recording {
    background: var(--danger);
    box-shadow: 0 4px 20px rgba(255,59,48,0.4);
    animation: orb-pulse 0.7s ease-in-out infinite;
}
.record-hint {
    font-size: 12px;
    color: var(--text-3);
    text-align: center;
}

/* ─── Access Screen ─── */
.access-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
}

.access-card {
    background: var(--surface);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 40px 32px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.access-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #007aff 0%, #5ac8fa 100%);
    flex-shrink: 0;
}

.access-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin: 0;
}

.access-desc {
    font-size: 14px;
    color: var(--text-2);
    text-align: center;
    margin: -4px 0 4px;
}

.access-input {
    width: 100%;
    text-align: center;
    font-size: 18px;
    letter-spacing: 3px;
    padding: 12px 16px;
}

.access-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--r-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.access-btn:hover { background: var(--primary-dark); }

.access-error {
    font-size: 13px;
    color: var(--danger);
    text-align: center;
}

.access-hint {
    font-size: 13px;
    color: var(--text-3);
}
.access-hint a { color: var(--primary); text-decoration: none; }

.hidden { display: none !important; }

/* ─── Mobile ─── */
@media (max-width: 600px) {
    body { padding: 0; align-items: stretch; }
    .app { border-radius: 0; height: 100dvh; max-height: none; }
    .settings-two-col { grid-template-columns: 1fr; }
    .message { max-width: 85%; font-size: 14px; }
}
