*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-hover: #f1f5f9;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --border: #e2e8f0;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

html { font-size: 14px; }
body {
    font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-hover); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 20px;
    font-size: 22px;
    font-weight: 800;
    color: var(--accent-hover);
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.5px;
}

.sidebar-nav { padding: 12px 0; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
    position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item.active { color: var(--accent-hover); background: rgba(99,102,241,0.1); }
.nav-item .nav-icon { font-size: 20px; width: 24px; text-align: center; }
.nav-badge {
    position: absolute; right: 16px;
    background: var(--danger); color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 1px 7px; border-radius: 10px;
    min-width: 20px; text-align: center;
}

.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-user img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-handle { font-size: 12px; color: var(--text-dim); }

.main-content { flex: 1; margin-left: 240px; min-height: 100vh; }
.content-area { max-width: 680px; margin: 0 auto; padding: 24px 16px; }
.content-wide { max-width: 960px; margin: 0 auto; padding: 24px 16px; }

/* === PAGE HEADER === */
.page-header { padding: 20px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.page-header h1 { font-size: 24px; font-weight: 700; }

/* === CARDS === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

/* === BUTTONS === */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius-xs);
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all 0.2s; text-decoration: none; white-space: nowrap; line-height: 1.4;
}
.btn:hover { opacity: 0.9; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--bg-input); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-input {
    width: 100%; padding: 10px 14px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-xs); color: var(--text);
    font-size: 14px; font-family: inherit; outline: none; transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(99,102,241,0.3); }
.form-input::placeholder { color: var(--text-dim); }
textarea.form-input { resize: vertical; min-height: 80px; }

/* === AVATAR === */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }
.avatar-lg { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }
.avatar-xl { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; background: var(--bg-input); }

/* === ALERT === */
.alert { padding: 12px 16px; border-radius: var(--radius-xs); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

/* === POST CARD === */
.post-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 20px; margin-bottom: 12px;
}
.post-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-user-info { flex: 1; }
.post-user-name { font-weight: 600; font-size: 14px; }
.post-user-name a { color: var(--text); }
.post-time { font-size: 12px; color: var(--text-dim); }
.post-content { font-size: 15px; line-height: 1.7; margin-bottom: 12px; word-break: break-word; }
.post-content .hashtag { color: var(--accent-hover); }
.post-images { margin-bottom: 12px; border-radius: var(--radius-sm); overflow: hidden; }
.post-images img { width: 100%; display: block; }
.post-images.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.post-images.grid-3 { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.post-images.grid-4 { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.post-actions { display: flex; gap: 4px; border-top: 1px solid var(--border); padding-top: 10px; }
.post-action-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; border: none; background: transparent;
    color: var(--text-dim); font-size: 13px; cursor: pointer;
    border-radius: var(--radius-xs); transition: all 0.2s;
}
.post-action-btn:hover { background: var(--bg-hover); color: var(--text); }
.post-action-btn.liked { color: var(--danger); }
.post-action-btn .count { font-weight: 600; }

/* === COMPOSER === */
.composer {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 20px;
}
.composer-top { display: flex; gap: 10px; }
.composer textarea {
    flex: 1; background: transparent; border: none; color: var(--text);
    font-size: 15px; resize: none; outline: none; min-height: 60px;
    font-family: inherit; line-height: 1.6;
}
.composer textarea::placeholder { color: var(--text-dim); }
.composer-actions {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.composer-tools { display: flex; gap: 8px; }
.composer-tool-btn {
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; color: var(--text-dim);
    font-size: 18px; cursor: pointer; border-radius: 50%; transition: all 0.2s;
}
.composer-tool-btn:hover { background: var(--bg-hover); color: var(--accent-hover); }

/* === MOBILE BOTTOM NAV === */
.mobile-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-card); border-top: 1px solid var(--border);
    z-index: 200; padding: 6px 0 env(safe-area-inset-bottom, 6px);
}
.mobile-nav-inner { display: flex; justify-content: space-around; align-items: center; }
.mobile-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 12px; color: var(--text-dim); font-size: 10px;
    text-decoration: none; position: relative;
}
.mobile-nav-item .nav-icon { font-size: 22px; }
.mobile-nav-item.active { color: var(--accent-hover); }
.mobile-nav-item .nav-badge { position: absolute; top: 0; right: 4px; font-size: 10px; padding: 0 5px; min-width: 16px; }

/* === AUTH PAGES === */
.auth-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow);
}
.auth-logo { font-size: 32px; font-weight: 800; color: var(--accent-hover); text-align: center; margin-bottom: 8px; letter-spacing: -1px; }
.auth-subtitle { text-align: center; color: var(--text-dim); margin-bottom: 28px; font-size: 14px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-dim); }

/* === CHAT === */
.chat-layout { display: flex; height: calc(100vh - 0px); }
.chat-sidebar {
    width: 320px; background: var(--bg-card); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden;
}
.chat-sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 18px; }
.chat-thread-list { flex: 1; overflow-y: auto; }
.chat-thread-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; cursor: pointer; transition: background 0.2s;
    border-bottom: 1px solid rgba(51,65,85,0.5);
}
.chat-thread-item:hover, .chat-thread-item.active { background: var(--bg-hover); }
.chat-thread-info { flex: 1; min-width: 0; }
.chat-thread-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-last { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-thread-time { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.chat-thread-unread { background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; }

.chat-main { flex: 1; display: flex; flex-direction: column; }
.chat-header { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; background: var(--bg-card); }
.chat-header-name { font-weight: 600; font-size: 16px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }

.chat-bubble {
    max-width: 70%; padding: 10px 14px; border-radius: 16px;
    font-size: 14px; line-height: 1.5; word-break: break-word; position: relative;
}
.chat-bubble.sent {
    align-self: flex-end; background: #00C300; color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-bubble.received {
    align-self: flex-start; background: var(--bg-input); color: var(--text);
    border-bottom-left-radius: 4px;
}
.chat-bubble-time { font-size: 10px; color: rgba(255,255,255,0.6); margin-top: 4px; text-align: right; }
.chat-bubble.received .chat-bubble-time { color: var(--text-dim); }
.chat-bubble.received { background: #e2e8f0; color: #1e293b; }
.chat-bubble-sender { font-size: 11px; color: var(--accent-hover); margin-bottom: 2px; font-weight: 600; }

.chat-input-area {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: flex-end; background: var(--bg-card);
}
.chat-input-area textarea {
    flex: 1; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 20px; padding: 10px 16px; color: var(--text);
    font-size: 14px; font-family: inherit; resize: none; outline: none;
    max-height: 120px; min-height: 40px; line-height: 1.4;
}
.chat-input-area textarea:focus { border-color: var(--accent); }
.chat-send-btn {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--accent); color: #fff; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 16px; transition: background 0.2s; flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--accent-hover); }

/* === PHOTO GRID === */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.photo-grid-item { position: relative; padding-bottom: 100%; overflow: hidden; cursor: pointer; }
.photo-grid-item img {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    object-fit: cover; transition: transform 0.3s;
}
.photo-grid-item:hover img { transform: scale(1.05); }

/* === FILE MANAGER === */
.file-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.file-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    transition: background 0.2s; cursor: pointer;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--bg-hover); }
.file-icon { font-size: 24px; width: 32px; text-align: center; color: var(--text-dim); }
.file-icon.folder { color: var(--warning); }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 12px; color: var(--text-dim); }
.file-actions { display: flex; gap: 6px; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding-bottom: 70px; }
    .mobile-nav { display: block; }
    .content-area, .content-wide { padding: 16px 12px; }
    .auth-card { padding: 28px 20px; }
    .chat-layout { flex-direction: column; }
    .chat-sidebar { width: 100%; height: auto; max-height: 40vh; }
    .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 2px; }
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* === TRANSITIONS === */
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* === UTILITIES === */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-accent { color: var(--accent-hover); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }
