/*
 * ManualDog Admin Styles
 * v1.0.0
 * This stylesheet handles the custom UI for the plugin's index and viewer pages.
 */

/* ==========================================================================
   1. Index Page Styles (List of all manuals)
   ========================================================================== */

.manualdog-index-page .manualdog-page-wrapper {
    background-color: #ffffff;
    margin-top: 20px;
    padding: 25px 40px;
    border: 1px solid #ccd0d4;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.manualdog-index-page .manualdog-page-header { text-align: center; margin-bottom: 40px; padding-bottom: 25px; border-bottom: 1px solid #eee; }
.manualdog-index-page .manualdog-page-header h1 { font-size: 2.2em; }
.manualdog-index-page .manualdog-manual-list { list-style: none; padding-left: 0; margin: 0; }
.manualdog-index-page .manualdog-manual-list a { font-size: 1.2em; text-decoration: none; display: block; padding: 10px 15px; border-radius: 4px; transition: background-color 0.2s, color 0.2s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.manualdog-index-page .manualdog-manual-list a:hover { background-color: #f0f6fc; color: #005a87; }

/* ==========================================================================
   2. Viewer Page (2-Column Layout) Styles
   ========================================================================== */

/* Fullscreen adjustment */
body.toplevel_page_manualdog_manual_index .wrap.manualdog-viewer-fullscreen,
body.manuals_page_manualdog_manual_viewer .wrap.manualdog-viewer-fullscreen { margin-left: -20px; }
.manualdog-viewer-fullscreen { display: flex; height: calc(100vh - 32px); overflow: hidden; position: relative; }

/* --- 2.1 Sidebar (Left Column) --- */
.manualdog-viewer-sidebar { width: 280px; background-color: #f0f0f1; border-right: 1px solid #dcdcde; display: flex; flex-direction: column; height: 100%; }
.manualdog-sidebar-header { padding: 15px 20px; border-bottom: 1px solid #dcdcde; flex-shrink: 0; }
.manualdog-sidebar-header a { display: flex; align-items: center; text-decoration: none; color: #1d2327; font-size: 16px; font-weight: 600; }
.manualdog-sidebar-header img { width: 36px; height: 36px; margin-right: 12px; }
.manualdog-sidebar-nav { overflow-y: auto; padding: 15px 0; flex-grow: 1; }
.manualdog-sidebar-nav-list { list-style: none; padding-left: 20px; margin: 0; }
.manualdog-sidebar-nav-list a { display: block; padding: 8px 15px; text-decoration: none; color: #444; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manualdog-sidebar-nav-list .current-manual > a,
.manualdog-sidebar-nav-list a:hover { background-color: #fff; color: #005a87; }
.manualdog-sidebar-nav-list .current-manual > a { font-weight: 600; }
.manualdog-sidebar-nav-list .level-1, .manualdog-sidebar-nav-list .level-2 { padding-left: 20px; }

/* --- 2.2 Main Content (Right Column) --- */
.manualdog-viewer-main { flex-grow: 1; background-color: #ffffff; display: flex; flex-direction: column; height: 100%; overflow-y: auto; transition: opacity 0.3s; }
.manualdog-main-header { padding: 20px 25px; border-bottom: 1px solid #eee; display: flex; justify-content: flex-start; align-items: center; }
.manualdog-main-title { font-size: 1.8em; margin: 0 15px; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; flex-grow: 1; }
.manualdog-main-header .page-title-action { margin-left: auto; }
.manualdog-main-content { padding: 25px; font-size: 16px; line-height: 1.8; flex-grow: 1; max-width: 840px; }
.manualdog-main-content h2, .manualdog-main-content h3 { margin-top: 2.5em; margin-bottom: 1em; }
.manualdog-main-content img { max-width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,.08); }

/* --- 2.3 Pager Footer (Previous/Next) --- */
.manualdog-main-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 25px;
    margin-top: auto;
    border-top: 1px solid #eee;
}
.manualdog-main-footer .pager-prev,
.manualdog-main-footer .pager-next {
    min-width: 0; /* Important for grid item truncation */
}
.manualdog-main-footer .pager-prev a,
.manualdog-main-footer .pager-next a {
    display: block;
    border: 1px solid #dcdcde;
    padding: 15px;
    border-radius: 8px;
    text-decoration: none;
    color: #1d2327;
    transition: background-color 0.2s;
    height: 100%;
}
.manualdog-main-footer .pager-prev a:hover,
.manualdog-main-footer .pager-next a:hover {
    background-color: #f6f7f7;
}
.manualdog-main-footer .pager-prev a strong,
.manualdog-main-footer .pager-next a strong {
    display: block;
    font-size: 12px;
    color: #646970;
    margin-bottom: 4px;
}
/* This is the final fix for title truncation */
.manualdog-main-footer .pager-prev a span,
.manualdog-main-footer .pager-next a span {
    font-size: 15px;
    font-weight: 500;
    display: block; /* Must be block for ellipsis to work */
    white-space: nowrap; /* Prevent wrapping */
    overflow: hidden; /* Hide overflowing text */
    text-overflow: ellipsis; /* Add ... */
}
.manualdog-main-footer .pager-next { text-align: right; }

/* ==========================================================================
   3. Sort Mode Styles
   ========================================================================== */

.manualdog-sort-controls {
    text-align: right;
    margin-bottom: 15px;
}
.manualdog-sort-notice {
    margin-top: 10px;
}
/* テーブル形式の管理リスト */
.manualdog-manage-table {
    margin-top: 16px;
}
.manualdog-manage-table .manualdog-col-handle {
    width: 30px;
    text-align: center;
}
.manualdog-manage-table .manualdog-col-title {
    transition: padding-left 0.2s;
}
.manualdog-manage-table .manualdog-col-actions a {
    text-decoration: none;
}
.manualdog-manage-table .manualdog-delete-link {
    color: #b32d2e;
}
.manualdog-manage-table .manualdog-delete-link:hover {
    text-decoration: underline;
}
/* ソートモード */
.manualdog-manage-table.is-sort-mode tr.manualdog-manage-item:hover {
    background-color: #f0f6fc;
    cursor: default;
}
.manualdog-manage-table.is-sort-mode tr.sortable-ghost {
    opacity: 0.4;
    background-color: #e0eeff !important;
}
.manualdog-manage-table.is-sort-mode tr.sortable-chosen {
    background-color: #f6f7f7;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
/* ダブルクリックヒント */
.manualdog-manage-table.is-sort-mode .manualdog-col-title {
    cursor: pointer;
}
.manualdog-manage-table.is-sort-mode .manualdog-col-title:hover::after {
    content: ' ✎';
    color: #72aee6;
    font-size: 0.8em;
}

/* All Manuals管理リスト（テーブル行） */
.manualdog-manage-table tr.manualdog-manage-item:hover {
    background-color: #f0f6fc;
}

.manualdog-sort-handle {
    display: none;
    cursor: grab;
    color: #aaa;
    margin-right: 6px;
    vertical-align: middle;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
}
.manualdog-sort-mode .manualdog-manual-list li {
    display: flex;
    align-items: center;
    border-radius: 4px;
    padding: 2px 0;
    transition: background-color 0.15s;
}
.manualdog-sort-mode .manualdog-manual-list li:hover {
    background-color: #f0f6fc;
}
.manualdog-sort-mode .manualdog-manual-list li a {
    pointer-events: none;
    flex-grow: 1;
}
.manualdog-sort-mode .manualdog-sort-handle {
    display: inline-flex;
}
.manualdog-sort-mode .manualdog-sort-handle:active {
    cursor: grabbing;
}
.manualdog-sort-mode .sortable-ghost {
    opacity: 0.4;
    background-color: #dce9f7;
}
.manualdog-sort-mode .sortable-chosen {
    background-color: #e8f0fa;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   4. Mobile Responsive Styles
   ========================================================================== */
.manualdog-sidebar-toggle { display: none; }
@media screen and (max-width: 782px) {
    body.toplevel_page_manualdog_manual_index .wrap.manualdog-viewer-fullscreen,
    body.manuals_page_manualdog_manual_viewer .wrap.manualdog-viewer-fullscreen { margin-left: -10px; }
    .manualdog-viewer-fullscreen { flex-direction: column; height: auto; min-height: calc(100vh - 46px); }
    .manualdog-viewer-sidebar { position: absolute; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.3s ease; z-index: 100; width: 280px; }
    .manualdog-viewer-fullscreen.sidebar-is-open .manualdog-viewer-sidebar { transform: translateX(0); box-shadow: 2px 0 10px rgba(0,0,0,0.1); }
    .manualdog-viewer-fullscreen.sidebar-is-open .manualdog-viewer-main { opacity: 0.5; pointer-events: none; }
    .manualdog-viewer-main { width: 100%; }
    .manualdog-main-header { padding: 15px; }
    .manualdog-main-title { font-size: 1.4em; margin: 0 10px; }
    .manualdog-main-content { padding: 20px; font-size: 15px; }
    .manualdog-main-footer { padding: 20px; grid-template-columns: 1fr; }
    .manualdog-sidebar-toggle { display: inline-flex; background: none; border: none; color: #50575e; padding: 5px; cursor: pointer; align-items: center; justify-content: center; }
    .manualdog-sidebar-toggle .dashicons { font-size: 28px; line-height: 1; }
}

/* ==========================================================================
   5. nestable2 Sort Page Styles
   ========================================================================== */

/* リセット・ベース */
.dd { position: relative; display: block; margin: 0; padding: 0; max-width: 100%; list-style: none; font-size: 14px; line-height: 20px; }
.dd-list { display: block; position: relative; margin: 0; padding: 0; list-style: none; }
.dd-list .dd-list { padding-left: 30px; }
.dd-item { display: block; position: relative; margin: 4px 0; padding: 0; min-height: 20px; font-size: 14px; line-height: 20px; }

/* ハンドル（ドラッグ可能エリア） */
.dd-handle {
    display: flex;
    align-items: center;
    height: 38px;
    margin: 0;
    padding: 0 12px;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    cursor: grab;
    transition: background-color 0.15s, border-color 0.15s;
    user-select: none;
}
.dd-handle:hover {
    background-color: #f0f6fc;
    border-color: #72aee6;
}
.dd-handle::before {
    content: '☰';
    color: #bbb;
    margin-right: 10px;
    font-size: 16px;
    flex-shrink: 0;
}

/* タイトル */
.manualdog-nestable-title {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ドラッグ中 */
.dd-dragel .dd-handle {
    background-color: #f0f6fc;
    border-color: #72aee6;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: grabbing;
}

/* ドロップ先のプレースホルダー */
.dd-placeholder {
    display: block;
    background: #e0eeff;
    border: 2px dashed #72aee6;
    border-radius: 4px;
    height: 38px;
    margin: 4px 0;
}

/* 折りたたみ状態 */
.dd-collapsed > .dd-list { display: none; }
.dd-collapsed > .dd-collapse { display: none; }
.dd-collapsed > .dd-expand { display: block; }

/* 折りたたみボタン */
.dd-collapse,
.dd-expand {
    display: block;
    position: absolute;
    cursor: pointer;
    width: 25px;
    height: 25px;
    font-size: 10px;
    line-height: 25px;
    text-align: center;
    color: #666;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 3px;
    right: 8px;
    top: 6px;
    z-index: 2;
}
.dd-expand { display: none; }
.dd-collapse:hover,
.dd-expand:hover {
    background-color: #f0f6fc;
    color: #135e96;
}