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

:root {
    --bg: #f8fafc;
    --white: #ffffff;
    --text: #3b342d;
    --text-accent: #5a4c3e;
    --text-light: #8b7355;
    --border: #e5e7eb;
    --sidebar-bg: #E8D9CD;
    --sidebar-light: #F2E6DA;
    --accent: #3b342d;
    --header-h: 52px;
    --tabs-h: 44px;
    --title-h: 62px;
    --actions-h: 58px;
    /* editor fills: 100vh - header - tabs - title - actions */
    --editor-h: calc(100vh - var(--header-h) - var(--tabs-h) - var(--title-h) - var(--actions-h));
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* ==============================
   APP SHELL
   ============================== */
.app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ── */
.app-header {
    height: var(--header-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--accent);
    color: #F4F2EF;
}

.app-title {
    font-size: 17px;
    font-weight: 700;
    color: #F4F2EF;
    letter-spacing: 0.3px;
}

.app-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.view-site-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 13px;
    background: rgba(244,242,239,0.12);
    color: rgba(244,242,239,0.8);
    border: 1px solid rgba(244,242,239,0.2);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
}
.view-site-btn:hover { background: rgba(244,242,239,0.22); color: #F4F2EF; text-decoration: none; }

.logout-btn {
    padding: 5px 13px;
    background: rgba(192,57,43,0.75);
    color: #F4F2EF;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.logout-btn:hover { background: #c0392b; }

/* ── Tabs ── */
.app-tabs {
    height: var(--tabs-h);
    flex-shrink: 0;
    display: flex;
    align-items: stretch;
    background: var(--white);
    border-bottom: 2px solid var(--border);
    padding: 0 20px;
}

.tab-btn {
    padding: 0 18px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-family: inherit;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text-accent); }

/* ── Tab Content ── */
.tab-content { display: none; }
.tab-content.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ==============================
   SHARED TITLE ROW
   ============================== */
.create-title-row,
.edit-title-row {
    height: var(--title-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 2px solid var(--border);
    background: var(--white);
}

#create-title,
.edit-title-input {
    flex: 1;
    font-size: 19px;
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    min-width: 0;
}
#create-title::placeholder,
.edit-title-input::placeholder { color: #9ca3af; font-weight: 400; }

.edit-id-input {
    width: 120px;
    flex-shrink: 0;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 11px;
    font-family: monospace;
    background: #f3f4f6;
    color: #6b7280;
    outline: none;
}

/* ==============================
   TAGS INLINE (in title row)
   ============================== */
.tags-inline {
    position: relative;
    flex-shrink: 0;
    width: 280px;
}

.tag-input-wrapper {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--white);
    min-height: 34px;
    cursor: text;
    overflow: clip;
}
.tag-input-wrapper:focus-within { border-color: var(--accent); }

.tag-pills-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    align-items: center;
    overflow-x: auto;
    flex: 1;
    min-width: 0;
    scrollbar-width: none;
}
.tag-pills-row::-webkit-scrollbar { display: none; }

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: #e8d9cd;
    color: var(--text);
    padding: 2px 6px 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.pill-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-accent);
    font-size: 12px;
    line-height: 1;
    padding: 0;
    width: 13px;
    height: 13px;
    border-radius: 50%;
}
.pill-remove:hover { background: var(--accent); color: #F4F2EF; }

.tag-text-input {
    border: none;
    outline: none;
    font-size: 12px;
    color: var(--text);
    background: transparent;
    min-width: 50px;
    flex: 1;
    font-family: inherit;
    padding: 0;
}
.tag-text-input::placeholder { color: #9ca3af; }

/* inline clear button (×) at end of wrapper */
.tag-input-wrapper .clear-tags-btn {
    display: inline-flex;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 15px;
    line-height: 1;
    padding: 0 2px;
    flex-shrink: 0;
}
.tag-input-wrapper .clear-tags-btn:hover { color: #c0392b; }

/* Suggestions panel — floats below */
.tags-inline .tag-suggestions-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 100%;
    min-width: 200px;
    z-index: 200;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 7px 9px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    max-height: 110px;
    overflow-y: auto;
}

.suggestion-pill {
    display: inline-flex;
    align-items: center;
    background: #f3f4f6;
    color: var(--text-accent);
    padding: 3px 9px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.suggestion-pill:hover { background: var(--accent); color: #F4F2EF; }

/* ==============================
   EDITOR WRAP
   ============================== */
.editor-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #f7f5f2;
    border-bottom: 1px solid var(--border);
}

/* Tell Toast UI to fill exactly */
.editor-wrap > div > .toastui-editor-defaultUI {
    height: var(--editor-h) !important;
    display: flex;
    flex-direction: column;
}

/* ==============================
   TOAST UI OVERRIDES
   ============================== */
.toastui-editor-defaultUI {
    border: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.toastui-editor-toolbar {
    border-bottom: 1px solid var(--border);
    background: #fafafa;
    flex-shrink: 0;
}

.toastui-editor-contents {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
    line-height: 1.75;
    padding: 16px 24px;
}

.toastui-editor-contents p { margin-bottom: 0.7em; }
.toastui-editor-contents h1,
.toastui-editor-contents h2,
.toastui-editor-contents h3 { color: var(--text); font-weight: 700; margin: 1em 0 0.4em; }
.toastui-editor-contents hr { border: none; border-top: 2px solid #e5e7eb; margin: 20px 0; }

/* ── Limit image size in editor ── */
.toastui-editor-contents img {
    max-height: 200px;
    max-width: 100%;
    width: auto;
    height: auto;
    display: block;
    margin: 8px 0;
    border-radius: 4px;
    cursor: pointer;
}

/* Selected image highlight */
.toastui-editor-contents img.img-selected {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.toastui-editor-mode-switch {
    border-top: 1px solid var(--border);
    background: #fafafa;
    flex-shrink: 0;
}

/* ==============================
   CREATE LAYOUT
   ============================== */
.create-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.create-actions {
    height: var(--actions-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    border-top: 2px solid var(--border);
    background: var(--white);
}

/* ==============================
   EDIT LAYOUT — split
   ============================== */
.edit-layout {
    display: grid;
    grid-template-columns: 270px 1fr;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Left sidebar ── */
.edit-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 2px solid var(--border);
    background: #fafafa;
    overflow: hidden;
}

.edit-sidebar-header {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.edit-sidebar-header input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: var(--white);
}
.edit-sidebar-header input:focus { border-color: var(--accent); }

.edit-sidebar-count {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 5px;
}

.post-list { flex: 1; overflow-y: auto; }

.post-list-item {
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
}
.post-list-item:hover { background: #f9fafb; }
.post-list-item.selected { background: #f0ede8; border-left: 3px solid var(--accent); padding-left: 11px; }

.post-list-title { font-weight: 600; color: var(--text); font-size: 13px; line-height: 1.4; margin-bottom: 2px; }
.post-list-meta { font-size: 11px; color: #9ca3af; margin-bottom: 4px; }
.post-list-tags { display: flex; flex-wrap: wrap; gap: 3px; }
.post-list-tag { font-size: 10px; background: var(--sidebar-bg); color: var(--text-accent); padding: 1px 6px; border-radius: 8px; font-weight: 600; }
.post-list-empty { padding: 28px 14px; text-align: center; color: #9ca3af; font-size: 13px; }

/* ── Right: editor ── */
.edit-main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.edit-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #9ca3af;
    font-size: 15px;
    font-style: italic;
}
.edit-empty-state i { font-size: 24px; opacity: 0.4; }

#editForm {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.edit-actions {
    height: var(--actions-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-top: 2px solid var(--border);
    background: var(--white);
    flex-wrap: wrap;
}

/* ==============================
   BUTTONS
   ============================== */
.submit-btn {
    background: var(--accent);
    color: #F4F2EF;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.submit-btn:hover { background: var(--text-accent); }
.submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.danger-btn {
    background: transparent;
    color: #c0392b;
    border: 1px solid rgba(192,57,43,0.4);
    padding: 7px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.danger-btn:hover { background: #c0392b; color: white; border-color: #c0392b; }

/* ==============================
   STATUS MESSAGES
   ============================== */
.status-message {
    padding: 7px 13px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
}
.status-message.success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.status-message.error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.status-message.loading { background: #f3f4f6; color: #374151; border: 1px solid var(--border); }

/* ==============================
   SCROLLBAR
   ============================== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* ==============================
   RESPONSIVE
   ============================== */
@media (max-width: 860px) {
    .edit-layout { grid-template-columns: 200px 1fr; }
    .tags-inline { width: 220px; }
}

@media (max-width: 640px) {
    .edit-layout { grid-template-columns: 1fr; }
    .edit-sidebar { max-height: 220px; border-right: none; border-bottom: 2px solid var(--border); }
    .create-title-row, .edit-title-row { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
    .tags-inline { width: 100%; }
}
