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

:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text: #1a1a1a;
    --text-muted: #888;
    --bg: #fafafa;
    --surface: #fff;
    --border: #e5e5e5;
    --error: #dc2626;
    --success: #22c55e;
    --hover-bg: #f5f5f7;
    --hover-radius: 8px;
    --status-new: #6366f1;
    --status-reviewing: #f59e0b;
    --status-ready: #22c55e;
    --status-published: #888;
    --input-padding: 0.5rem 0.75rem;
    --input-radius: 6px;
    --touch-min: 44px;
    --thumb-width: 280px;
    --thumb-radius: 8px;
    --tab-active-border: #6366f1;
    --tab-inactive-text: #888;
}

html, body { height: 100%; overflow: hidden; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    max-width: 100%;
}
.header-left, .header-right { display: flex; align-items: center; gap: 0.5rem; min-width: 80px; }
.header-left { justify-content: flex-start; }
.header-right { justify-content: flex-end; }
.header-center { font-weight: 600; text-align: center; flex: 1; }
.header-link { color: var(--primary); text-decoration: none; }
.header-link:hover { color: var(--primary-hover); }

/* Avatar */
.avatar-wrapper { position: relative; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none; cursor: pointer;
    font-weight: 600; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
}
.avatar-dropdown {
    display: none; position: absolute; right: 0; top: 100%; margin-top: 0.5rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; min-width: 160px; z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.avatar-dropdown.open { display: block; }
.dropdown-name { padding: 0.75rem 1rem; font-weight: 600; border-bottom: 1px solid var(--border); }
.dropdown-item {
    display: block; width: 100%; padding: 0.75rem 1rem; border: none;
    background: none; text-align: left; cursor: pointer; color: var(--text);
    text-decoration: none; font-size: 14px;
}
.dropdown-item:hover { background: var(--hover-bg); }
.dropdown-logout { color: var(--error); }

/* Content */
.content {
    flex: 1; overflow-y: auto; display: flex; flex-direction: column;
    align-items: center; padding: 0;
}
.content::-webkit-scrollbar { display: none; }
.content { scrollbar-width: none; }
.content-unauth {
    height: 100vh; display: flex; align-items: center; justify-content: center;
}

.app-container {
    width: 70%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* Auth */
.auth-card {
    background: var(--surface); padding: 2rem; border-radius: 12px;
    border: 1px solid var(--border); width: 100%; max-width: 400px;
}
.auth-card h1 { margin-bottom: 1.5rem; text-align: center; }
.auth-footer { text-align: center; margin-top: 1rem; color: var(--text-muted); font-size: 14px; }
.auth-footer a { color: var(--primary); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-size: 14px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: var(--input-padding);
    border: 1px solid var(--border); border-radius: var(--input-radius);
    font-size: 16px; background: var(--surface); color: var(--text);
}
.form-group textarea { resize: vertical; font-family: inherit; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.5rem 1rem; border-radius: var(--input-radius); border: none;
    font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none;
    min-height: var(--touch-min); transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--hover-bg); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 0.25rem 0.75rem; min-height: auto; font-size: 13px; }
.btn-full { width: 100%; }
.btn-icon {
    background: none; border: none; cursor: pointer; padding: 0.25rem;
    color: var(--text-muted); display: inline-flex; align-items: center;
}
.btn-icon:hover { color: var(--text); }

/* Header action button */
.header-action-btn {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.header-action-btn:hover { background: var(--primary-hover); }

/* Dashboard */
.dashboard-container {
    width: 70%; max-width: 480px; margin: 0 auto; padding: 1.5rem 0;
}
.dashboard-search { margin-bottom: 1rem; }
.dashboard-search input {
    width: 100%; padding: var(--input-padding);
    border: 1px solid var(--border); border-radius: var(--input-radius);
    font-size: 16px;
}
.app-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem; border-radius: var(--hover-radius);
    text-decoration: none; color: var(--text); transition: background 0.15s;
}
.app-row:hover { background: var(--hover-bg); }
.app-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.app-name { font-weight: 500; }

/* Empty state */
.empty-state { color: var(--text-muted); text-align: center; padding: 2rem; }

/* Messages */
.error-message { color: var(--error); background: #fef2f2; padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; font-size: 14px; }
.success-message { color: var(--success); background: #f0fdf4; padding: 0.75rem; border-radius: 6px; margin-bottom: 1rem; font-size: 14px; }
.text-muted { color: var(--text-muted); font-size: 14px; }

/* Admin */
.admin-layout {
    display: flex; width: 100%; flex: 1; min-height: 0;
}
.admin-tabs {
    display: flex; flex-direction: column; gap: 0.25rem;
    padding: 1rem; border-right: 1px solid var(--border);
    min-width: 160px; background: var(--surface);
}
.tab-btn {
    padding: 0.75rem 1rem; border: none; background: none;
    text-align: left; cursor: pointer; border-radius: var(--hover-radius);
    font-size: 14px; color: var(--tab-inactive-text); white-space: nowrap;
}
.tab-btn:hover { background: var(--hover-bg); }
.tab-btn.active {
    color: var(--primary); background: var(--hover-bg);
    border-left: 3px solid var(--tab-active-border);
}
.admin-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.admin-panel { max-width: 480px; }
.admin-panel h2 { margin-bottom: 1rem; font-size: 18px; }

.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; }
.info-label { color: var(--text-muted); font-size: 14px; }
.info-value { font-size: 14px; }

.backup-list { display: flex; flex-direction: column; gap: 0.5rem; }
.backup-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.backup-info { display: flex; flex-direction: column; gap: 0.25rem; }
.backup-name { font-size: 13px; font-family: monospace; }

/* List view */
.list-container { flex: 1; overflow-y: auto; min-height: 0; }
.list-container::-webkit-scrollbar { display: none; }
.list-container { scrollbar-width: none; }

.group-header {
    padding: 0.5rem 0.75rem; font-size: 13px; font-weight: 600;
    color: var(--text-muted); position: sticky; top: 0;
    background: var(--bg); z-index: 10;
}

.list-item {
    display: flex; align-items: flex-start; justify-content: space-between;
    padding: 1rem 0.75rem; cursor: pointer; position: relative;
    border-bottom: 1px solid var(--border); margin: 0.25rem 0;
    border-radius: var(--hover-radius); transition: background 0.15s;
}
.list-item:hover { background: var(--hover-bg); }
.list-item:hover .item-delete { opacity: 1; }

.item-content { flex: 1; min-width: 0; }
.item-primary { font-weight: 500; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.item-meta {
    display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem;
    margin-top: 0.25rem; font-size: 13px; color: var(--text-muted);
}
.item-meta-left { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; flex: 1; }
.item-meta-right { display: flex; gap: 0.5rem; align-items: center; }
.item-meta-sep::before { content: "·"; margin: 0 0.125rem; }
.item-time { color: var(--text-muted); font-size: 13px; white-space: nowrap; margin-left: 0.5rem; flex-shrink: 0; }
.item-delete {
    opacity: 0; transition: opacity 0.15s;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 0.25rem; display: flex; align-items: center;
}
.item-delete:hover { color: var(--error); }

.item-expanded { -webkit-line-clamp: unset; }

/* Columns / table view */
.list-table { width: 100%; border-collapse: collapse; }
.list-table th {
    text-align: left; padding: 0.5rem 0.75rem; font-size: 13px;
    font-weight: 600; color: var(--text-muted);
    border-bottom: 2px solid var(--border); position: sticky; top: 0;
    background: var(--bg); z-index: 10;
}
.list-table td {
    padding: 0.75rem; border-bottom: 1px solid var(--border); font-size: 14px;
}
.list-table tr { cursor: pointer; transition: background 0.15s; }
.list-table tr:hover { background: var(--hover-bg); }

/* Status badge */
.status-badge {
    display: inline-block; padding: 0.125rem 0.5rem;
    border-radius: 999px; font-size: 12px; font-weight: 500;
    text-transform: capitalize;
}
.status-new { background: var(--status-new); color: #fff; }
.status-reviewing { background: var(--status-reviewing); color: #fff; }
.status-ready { background: var(--status-ready); color: #fff; }
.status-published { background: var(--status-published); color: #fff; }

/* Search */
.search-row { display: flex; justify-content: flex-end; padding: 0.5rem 0; align-items: center; }
.search-icon { cursor: pointer; color: var(--text-muted); display: flex; align-items: center; padding: 0.25rem; }
.search-icon:hover { color: var(--text); }
.search-active {
    display: flex; align-items: center; gap: 0.5rem;
    justify-content: center;
}
.search-input {
    width: 20ch; padding: var(--input-padding);
    border: 1px solid var(--border); border-radius: var(--input-radius);
    font-size: 14px;
}
.search-input:focus { outline: none; border-color: var(--primary); }
.search-compact {
    display: flex; align-items: center; gap: 0.25rem;
    cursor: pointer; font-size: 13px; color: var(--text-muted);
}

/* Page actions */
.page-actions-row {
    display: flex; justify-content: flex-end; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0;
}
.info-line { font-size: 13px; color: var(--text-muted); }

/* Input bar */
.input-bar { padding: 0.5rem 0; }
.input-bar textarea {
    width: 100%; padding: var(--input-padding);
    border: 1px solid var(--border); border-radius: var(--input-radius);
    font-size: 16px; font-family: inherit; resize: none;
    rows: 3; min-height: calc(3 * 1.5em + 1rem);
}
.input-bar textarea:focus { outline: none; border-color: var(--primary); }

/* Compose overlay */
.compose-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 300;
    align-items: center; justify-content: center;
}
.compose-box {
    background: var(--surface); border-radius: 12px;
    display: flex; flex-direction: column;
    position: absolute; top: 10%; left: 10%; right: 10%; bottom: 10%;
}
.compose-box.fullscreen { top: 0; left: 0; right: 0; bottom: 0; border-radius: 0; }
.compose-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
}
.compose-title { font-weight: 600; }
.compose-icons { display: flex; gap: 0.5rem; align-items: center; }
.compose-textarea {
    flex: 1; border: none; padding: 1rem 1.5rem; font-size: 16px;
    font-family: inherit; resize: none; outline: none;
}
.compose-status {
    padding: 0.5rem 1.5rem; border-top: 1px solid var(--border);
    font-size: 13px; color: var(--text-muted); text-align: right;
}

/* Overlay / Modal */
.overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 300;
    display: flex; align-items: center; justify-content: center;
}
.modal-box {
    background: var(--surface); border-radius: 12px;
    width: 90%; max-width: 600px; max-height: 80vh;
    overflow-y: auto; padding: 1.5rem; position: relative;
}
.modal-close {
    position: absolute; top: 0.75rem; right: 0.75rem;
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    display: flex; align-items: center;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-weight: 600; margin-bottom: 1rem; }

/* Entry form modal */
.entry-form-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 300;
    align-items: center; justify-content: center;
}
.entry-form-box {
    background: var(--surface); border-radius: 12px;
    width: 50%; max-width: 480px; max-height: 90vh; overflow-y: auto;
    padding: 1.5rem; position: relative;
}

/* Confirm dialog */
.confirm-box {
    background: var(--surface); border-radius: 12px;
    padding: 1.5rem; width: 90%; max-width: 360px; text-align: center;
}
.confirm-box p { margin-bottom: 1.5rem; }
.confirm-actions { display: flex; justify-content: center; gap: 0.75rem; }

/* Detail view */
.detail-container { width: 100%; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.detail-hero { padding: 1.5rem 0; }
.detail-hero h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.detail-hero-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.detail-fields { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem 1rem; padding: 1rem 0; }
.detail-field-label { color: var(--text-muted); font-size: 14px; }
.detail-field-value { font-size: 14px; }
.detail-field-value[contenteditable="true"]:focus { outline: 2px solid var(--primary); border-radius: 4px; padding: 0 4px; }
.detail-field-empty { color: var(--text-muted); font-style: italic; }
.detail-actions { padding: 1rem 0; display: flex; gap: 0.75rem; }

/* Tabs (horizontal) */
.tabs-horizontal { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tab-bar-h {
    display: flex; gap: 0; border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}
.tab-h {
    padding: 0.75rem 1.25rem; border: none; background: none;
    cursor: pointer; font-size: 14px; font-weight: 500;
    color: var(--tab-inactive-text); border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: color 0.15s;
}
.tab-h.active { color: var(--primary); border-bottom-color: var(--tab-active-border); }
.tab-h:hover { color: var(--text); }
.tab-content-h { flex: 1; overflow-y: auto; min-height: 0; padding: 1rem 0; }
.tab-content-h::-webkit-scrollbar { display: none; }
.tab-content-h { scrollbar-width: none; }

/* Media */
.media-section { padding: 1rem 0; }
.media-section-label { font-weight: 600; margin-bottom: 0.75rem; font-size: 14px; color: var(--text-muted); }
.media-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.media-thumb {
    width: var(--thumb-width); aspect-ratio: 16/9;
    border-radius: var(--thumb-radius); overflow: hidden;
    position: relative; cursor: pointer; background: #000;
}
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb-play {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    color: #fff; opacity: 0.8;
}
.media-empty { color: var(--text-muted); font-size: 13px; font-style: italic; padding: 0.5rem 0; }

/* Sections */
.section-label { font-weight: 600; font-size: 14px; color: var(--text-muted); margin: 1rem 0 0.5rem; }

/* Editor select */
.editor-select { padding: 0.5rem 0; }
.editor-value { font-size: 14px; }
.editor-input { width: 100%; max-width: 300px; }

/* Link fields */
.detail-link { color: var(--primary); text-decoration: none; display: inline-flex; align-items: center; gap: 0.25rem; }
.detail-link:hover { text-decoration: underline; }

/* Progress dialog */
.progress-dialog {
    background: var(--surface); border-radius: 12px;
    padding: 1.5rem; width: 90%; max-width: 400px; text-align: center;
}
.progress-bar-container {
    width: 100%; height: 8px; background: var(--border);
    border-radius: 4px; margin: 1rem 0; overflow: hidden;
}
.progress-bar-fill {
    height: 100%; background: var(--primary);
    border-radius: 4px; transition: width 0.3s;
}
.progress-step { font-size: 14px; color: var(--text-muted); margin-bottom: 0.5rem; }

/* Video player modal */
.video-modal { padding: 0; background: #000; border-radius: 8px; overflow: hidden; max-width: 90vw; }
.video-modal video { width: 100%; max-height: 80vh; }

/* Image modal */
.image-modal { padding: 0; background: transparent; max-width: 90vw; }
.image-modal img { max-width: 100%; max-height: 90vh; border-radius: 8px; }

/* Setup view */
.setup-container { max-width: 480px; margin: 2rem auto; }
.setup-step {
    display: flex; align-items: flex-start; gap: 1rem;
    padding: 1.25rem 0; border-bottom: 1px solid var(--border);
}
.setup-step-icon {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
}
.setup-step-pending { background: var(--border); color: var(--text-muted); }
.setup-step-done { background: var(--success); color: #fff; }
.setup-step-content { flex: 1; }
.setup-step-label { font-weight: 500; margin-bottom: 0.5rem; }

/* Suggestion list */
.suggest-wrapper { position: relative; }
.suggest-list {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--input-radius); z-index: 50;
    max-height: 200px; overflow-y: auto;
    display: none;
}
.suggest-list.open { display: block; }
.suggest-item {
    padding: 0.5rem 0.75rem; cursor: pointer; font-size: 14px;
}
.suggest-item:hover { background: var(--hover-bg); }

/* Folder browser */
.folder-list { display: flex; flex-direction: column; gap: 0.25rem; }
.folder-item {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem;
    cursor: pointer; border-radius: var(--hover-radius); font-size: 14px;
}
.folder-item:hover { background: var(--hover-bg); }
.folder-breadcrumb { display: flex; gap: 0.25rem; font-size: 13px; color: var(--text-muted); margin-bottom: 0.5rem; flex-wrap: wrap; }
.folder-breadcrumb a { color: var(--primary); text-decoration: none; }

/* Load more */
.load-more { text-align: center; padding: 1rem; }
.load-more button { color: var(--primary); background: none; border: none; cursor: pointer; font-size: 14px; }

/* Detail select widget */
.detail-select {
    padding: var(--input-padding); border: 1px solid var(--border);
    border-radius: var(--input-radius); font-size: 14px; background: var(--surface);
}

/* Mobile */
@media (max-width: 768px) {
    .content { padding: 0; }
    .app-container { width: 100%; padding: 0 0.75rem; }
    .dashboard-container { width: 100%; padding: 1rem 0.75rem; }
    .header-inner { padding: 0.75rem; }

    .list-item { flex-direction: column; padding: 0.75rem; }
    .item-time { margin-left: 0; margin-top: 0.25rem; }
    .item-meta { flex-direction: column; }

    .compose-box { top: 0; left: 0; right: 0; bottom: 0; border-radius: 0; }
    .compose-fullscreen-toggle { display: none; }
    .entry-form-box { width: 100%; max-width: 100%; height: 100%; border-radius: 0; max-height: 100%; }

    .admin-layout { flex-direction: column; }
    .admin-tabs {
        flex-direction: row; border-right: none;
        border-bottom: 1px solid var(--border);
        min-width: auto; overflow-x: auto; padding: 0.5rem;
    }
    .tab-btn.active { border-left: none; border-bottom: 2px solid var(--tab-active-border); }

    .media-thumb { width: 100%; }

    .list-table { font-size: 13px; }
    .list-table th, .list-table td { padding: 0.5rem; }
}
