* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #ffffff;
    --bg2: #f9f9f9;
    --surface: #f0f0f0;
    --border: #e5e5e5;
    --text: #1a1a1a;
    --text2: #6b6b6b;
    --text3: #999;
    --accent: #1a1a1a;
    --green: #10a37f;
    --radius: 14px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

/* ===== Overlay ===== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 90;
    transition: opacity 0.3s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== Drawer ===== */
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: var(--bg2);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
    border-right: 1px solid var(--border);
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.drawer-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.88rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    transition: background 0.2s;
}

.new-chat-btn:active {
    background: var(--surface);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 12px;
}

.chat-history::-webkit-scrollbar {
    display: none;
}

.history-item {
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 0.84rem;
    color: var(--text2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
}

.history-item:active,
.history-item.active {
    background: var(--surface);
    color: var(--text);
}

.drawer-btn {
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text2);
    font-size: 0.84rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

.drawer-btn:active {
    color: var(--text);
}

/* ===== App ===== */
.app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
    padding: 12px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.icon-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--text2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.icon-btn:active {
    background: var(--surface);
}

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

.app-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
}

.model-badge {
    font-size: 0.65rem;
    font-weight: 500;
    background: var(--surface);
    padding: 3px 8px;
    border-radius: 6px;
    color: var(--text2);
}

/* ===== Chat Area ===== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.chat-area::-webkit-scrollbar {
    display: none;
}

/* Welcome */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 40px 20px;
}

.welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 800;
    color: #fff;
    margin-bottom: 8px;
}

.welcome-icon.small {
    width: 44px;
    height: 44px;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.welcome h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.welcome p {
    color: var(--text2);
    font-size: 0.9rem;
}

/* ===== Messages ===== */
.message-row {
    padding: 6px 16px;
    animation: fadeIn 0.25s ease;
}

/* User - bubble abu muda, rata kanan */
.message-row.user {
    display: flex;
    justify-content: flex-end;
}

.message-row.user .msg-bubble {
    background: #e9e9eb;
    color: var(--text);
    border-radius: 20px 20px 4px 20px;
    max-width: 85%;
    padding: 10px 16px;
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Assistant - tanpa bubble, teks biasa */
.message-row.assistant {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 16px;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    margin-top: 2px;
}

.message-row.assistant .msg-bubble {
    color: var(--text);
    max-width: 88%;
    font-size: 0.9rem;
    line-height: 1.7;
    word-wrap: break-word;
    white-space: pre-wrap;
    padding-top: 3px;
}

/* Typing */
.typing .msg-bubble::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text2);
    margin-left: 4px;
    vertical-align: middle;
    border-radius: 50%;
    animation: blink 0.8s infinite;
}

/* ===== Input ===== */
.input-wrapper {
    padding: 10px 12px;
    padding-bottom: calc(10px + var(--safe-bottom));
    flex-shrink: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.input-box {
    display: flex;
    align-items: flex-end;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s;
}

.input-box:focus-within {
    border-color: #bbb;
}

.input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 8px 0;
}

.input-box textarea::placeholder {
    color: var(--text3);
}

.input-box button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.15s;
}

.input-box button:active {
    transform: scale(0.92);
}

.input-box button:disabled {
    opacity: 0.3;
}

/* ===== Bottom Sheet ===== */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: opacity 0.3s;
}

.sheet-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.sheet-overlay.hidden .sheet {
    transform: translateY(100%);
}

.sheet {
    background: var(--bg);
    border-radius: 16px 16px 0 0;
    padding: 12px 20px 24px;
    padding-bottom: calc(24px + var(--safe-bottom));
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    transition: transform 0.35s ease;
    border-top: 1px solid var(--border);
}

.sheet::-webkit-scrollbar {
    display: none;
}

.sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.sheet h2 {
    font-size: 1.05rem;
    margin-bottom: 20px;
    color: var(--text);
}

/* Welcome modal */
.welcome-modal {
    text-align: center;
    padding: 8px 0;
}

.welcome-modal h2 {
    margin-bottom: 6px;
}

.welcome-modal p {
    color: var(--text2);
    font-size: 0.82rem;
    margin-bottom: 20px;
}

.welcome-modal input {
    text-align: center;
}

/* Settings */
.setting-group {
    margin-bottom: 18px;
}

.setting-group label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.setting-group input,
.setting-group select,
.setting-group textarea,
.welcome-modal input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.setting-group input:focus,
.setting-group select:focus,
.setting-group textarea:focus,
.welcome-modal input:focus {
    border-color: #999;
}

.setting-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23999' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.setting-group select option {
    background: var(--bg);
}

.setting-group textarea {
    resize: vertical;
    min-height: 70px;
    line-height: 1.5;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity 0.2s;
}

.btn-primary:active {
    opacity: 0.8;
}

.btn-secondary {
    width: 100%;
    padding: 13px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text2);
    font-size: 0.88rem;
    cursor: pointer;
    margin-top: 8px;
}

.btn-secondary:active {
    background: var(--bg2);
}

.hidden {
    display: none;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}
