/* ============================================================
   Kurgucu AI — Dark / glassmorphism
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

:root {
    --bg-0: #07080b;
    --bg-1: #0d0f14;
    --bg-2: #12151c;
    --bg-3: #1a1e27;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --text: #e9ecf1;
    --text-dim: #8b91a1;
    --text-faint: #565d6d;
    --accent: #e31e24;
    --accent-2: #ff4d52;
    --accent-soft: rgba(227, 30, 36, 0.12);
    --ok: #2fd67e;
    --warn: #f5b84a;
    --user-bubble: linear-gradient(135deg, #1c2030 0%, #141826 100%);
    --assistant-bubble: linear-gradient(135deg, rgba(227,30,36,0.08) 0%, rgba(18,21,28,0.95) 100%);
    --radius: 14px;
    --radius-sm: 8px;
    --shadow-lg: 0 20px 50px -10px rgba(0,0,0,0.5);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-0);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* Grain texture on body */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ================== LOGIN ================== */
.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at top, rgba(227,30,36,0.12), transparent 60%),
        radial-gradient(ellipse at bottom left, rgba(80,80,200,0.08), transparent 50%),
        var(--bg-0);
    padding: 20px;
}
.login-card {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 40px 36px;
    background: rgba(18,21,28,0.7);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
}
.login-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.01em;
}
.login-logo.small { font-size: 15px; }
.logo-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.9); }
}
.login-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin: 8px 0 28px;
}
.login-form label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
}
.login-form input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.login-form input[type="password"]:focus {
    border-color: var(--accent);
    background: var(--bg-3);
}
.login-form button {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: background 0.15s, transform 0.05s;
}
.login-form button:hover { background: var(--accent-2); }
.login-form button:active { transform: scale(0.98); }
.login-error {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--accent-2);
}

/* ================== APP LAYOUT ================== */
.app-body {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    background: var(--bg-0);
    position: relative;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    padding: 16px;
    gap: 14px;
    overflow: hidden;
    z-index: 1;
}
.sidebar-header { padding: 4px 2px 6px; }

.mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--bg-2);
    border-radius: var(--radius-sm);
}
.mode-btn {
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    border-radius: 6px;
    transition: all 0.15s;
}
.mode-btn.active {
    background: var(--bg-3);
    color: var(--text);
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.mode-btn:hover:not(.active) { color: var(--text); }

.new-chat-btn {
    padding: 11px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: background 0.15s, transform 0.05s;
}
.new-chat-btn:hover { background: var(--accent-2); }
.new-chat-btn:active { transform: scale(0.98); }

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    padding: 4px 2px 0;
    font-weight: 600;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 -6px;
    padding: 0 6px;
}
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }

.chat-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.1s;
    color: var(--text-dim);
    font-size: 13px;
}
.chat-item:hover { background: var(--bg-2); color: var(--text); }
.chat-item.active { background: var(--bg-3); color: var(--text); }
.chat-item-badge {
    display: inline-flex;
    width: 20px; height: 20px;
    align-items: center; justify-content: center;
    font-size: 10px;
    font-weight: 700;
    border-radius: 4px;
    background: var(--bg-3);
    color: var(--text-dim);
}
.chat-item-badge.kurgu { background: var(--accent-soft); color: var(--accent-2); }
.chat-item-badge.serbest { background: rgba(100,120,200,0.15); color: #8ea0dd; }
.chat-item-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.chat-item-del {
    opacity: 0;
    color: var(--text-faint);
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.1s;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { background: rgba(255,80,80,0.15); color: var(--accent-2); }

.empty-hint {
    padding: 16px 10px;
    font-size: 12px;
    color: var(--text-faint);
    text-align: center;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.ghost-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    text-align: left;
}
.ghost-btn:hover { background: var(--bg-2); color: var(--text); border-color: var(--border-strong); }
.ghost-btn.small { padding: 6px 10px; font-size: 12px; }
.ghost-btn.tiny { padding: 4px 8px; font-size: 11px; }
.memory-count {
    display: inline-flex;
    min-width: 20px; height: 20px;
    padding: 0 6px;
    align-items: center; justify-content: center;
    background: var(--accent-soft);
    color: var(--accent-2);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}

/* Main */
.main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background:
        radial-gradient(ellipse at top right, rgba(227,30,36,0.05), transparent 50%),
        var(--bg-0);
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(13,15,20,0.7);
    backdrop-filter: blur(12px);
}
.main-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}
.mode-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent-soft);
    color: var(--accent-2);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.mode-badge.serbest { background: rgba(100,120,200,0.15); color: #8ea0dd; }

.chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    position: relative;
}
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }

.message-wrapper {
    padding: 8px 24px;
    max-width: 860px;
    margin: 0 auto;
}
.message {
    display: flex;
    gap: 14px;
    padding: 16px 18px;
    border-radius: var(--radius);
    animation: slideIn 0.3s ease-out;
}
@keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.message.user {
    background: var(--user-bubble);
    border: 1px solid var(--border);
}
.message.assistant {
    background: var(--assistant-bubble);
    border: 1px solid var(--border);
}
.msg-avatar {
    flex-shrink: 0;
    width: 30px; height: 30px;
    border-radius: 8px;
    display: grid; place-items: center;
    font-size: 12px;
    font-weight: 700;
    background: var(--bg-3);
    color: var(--text-dim);
}
.message.user .msg-avatar { background: var(--bg-2); color: var(--text); }
.message.assistant .msg-avatar { background: var(--accent); color: white; box-shadow: 0 2px 8px var(--accent-soft); }
.msg-content {
    flex: 1;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.65;
}
.msg-content code {
    background: var(--bg-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
    font-size: 12px;
}
.msg-content pre {
    background: var(--bg-2);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid var(--border);
}
.msg-content pre code {
    background: transparent;
    padding: 0;
}
.msg-content h1, .msg-content h2, .msg-content h3 {
    margin: 14px 0 6px;
    font-weight: 600;
}
.msg-content ul, .msg-content ol { margin: 8px 0; padding-left: 22px; }
.msg-content li { margin: 3px 0; }
.msg-content table {
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}
.msg-content th, .msg-content td {
    padding: 6px 10px;
    border: 1px solid var(--border);
}
.msg-content th { background: var(--bg-2); font-weight: 600; }

.msg-meta {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .msg-meta { opacity: 1; }
.msg-meta button {
    font-size: 11px;
    color: var(--text-faint);
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--bg-2);
}
.msg-meta button:hover { color: var(--text); background: var(--bg-3); }

.typing {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}
.typing span {
    width: 6px; height: 6px;
    background: var(--text-dim);
    border-radius: 50%;
    animation: dot 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.welcome {
    max-width: 640px;
    margin: 60px auto 20px;
    padding: 0 24px;
    text-align: center;
}
.welcome h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 10px;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.welcome p {
    color: var(--text-dim);
    margin: 0 0 24px;
}
.example-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.chip {
    padding: 8px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-dim);
    font-size: 12px;
    transition: all 0.15s;
}
.chip:hover {
    background: var(--bg-3);
    color: var(--text);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

/* Composer */
.composer {
    padding: 14px 24px 18px;
    border-top: 1px solid var(--border);
    background: rgba(13,15,20,0.7);
    backdrop-filter: blur(12px);
}
.composer-inner {
    max-width: 860px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    transition: border-color 0.15s;
}
.composer-inner:focus-within {
    border-color: var(--border-strong);
    background: var(--bg-3);
}
.composer-inner textarea {
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    padding: 8px 10px;
    max-height: 180px;
    color: var(--text);
}
.composer-inner textarea::placeholder { color: var(--text-faint); }
.send-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    background: var(--accent);
    color: white;
    border-radius: 10px;
    align-self: end;
    transition: background 0.15s, transform 0.05s;
}
.send-btn:hover { background: var(--accent-2); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--bg-3); color: var(--text-faint); cursor: not-allowed; }
.composer-hint {
    max-width: 860px;
    margin: 6px auto 0;
    font-size: 11px;
    color: var(--text-faint);
    text-align: right;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 18px;
    background: var(--bg-3);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease-out;
    z-index: 100;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: var(--accent); color: var(--accent-2); }
.toast.success { border-color: var(--ok); color: var(--ok); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 50;
    padding: 24px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-panel {
    position: relative;
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--bg-1);
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease-out;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.modal-header h2 { font-size: 18px; margin: 0; }
.modal-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin: 0 0 20px;
}
.memory-add {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 20px;
}
.memory-add textarea {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    outline: none;
    resize: vertical;
    min-height: 40px;
}
.memory-add textarea:focus { border-color: var(--border-strong); }
.primary-btn {
    padding: 10px 18px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    white-space: nowrap;
}
.primary-btn:hover { background: var(--accent-2); }

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.memory-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.memory-content {
    flex: 1;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text);
}

@media (max-width: 720px) {
    .app-body { grid-template-columns: 1fr; }
    .sidebar {
        position: absolute;
        left: 0; top: 0; bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
}
