/* ==========================================================================
   记事文档编辑器（文字 + 表格混排）  memodoc.css
   ========================================================================== */

.md-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 41, 38, 0.42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: mdFade .18s ease;
}
@keyframes mdFade { from { opacity: 0; } to { opacity: 1; } }

.md-dialog {
    width: min(1200px, 100%);
    height: min(860px, 100%);
    background: #FFFDFA;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(45, 41, 38, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: mdPop .22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes mdPop { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- 头部 ---------- */
.md-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #EFE8E0;
    background: #FFFDFA;
    flex: none;
}
.md-head-title {
    font-size: 15px;
    font-weight: 600;
    color: #2D2926;
    white-space: nowrap;
}
.md-head-spacer { flex: 1; }
.md-title-input {
    flex: 1;
    min-width: 120px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid #EFE8E0;
    border-radius: 9px;
    background: #FDFAF6;
    font-family: inherit;
    font-size: 13px;
    color: #2D2926;
    outline: none;
}
.md-title-input:focus { border-color: #C2855B; background: #FFF; }
.md-x {
    width: 30px; height: 30px;
    border: none; background: none;
    font-size: 22px; line-height: 1;
    color: #A79E95; cursor: pointer; border-radius: 8px;
}
.md-x:hover { background: #F4EFE8; color: #2D2926; }

/* ---------- 工具栏 ---------- */
.md-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid #EFE8E0;
    background: #FBF7F1;
    flex: none;
    position: relative;
    z-index: 5;
}
.md-tb-group {
    display: flex;
    align-items: center;
    gap: 3px;
    padding-right: 8px;
    margin-right: 2px;
    border-right: 1px solid #E7DFD6;
}
.md-tb-group:last-child { border-right: none; padding-right: 0; }
.md-tb-label {
    font-size: 11px;
    color: #9A9088;
    margin-right: 2px;
    white-space: nowrap;
}
.md-btn {
    height: 28px;
    min-width: 28px;
    padding: 0 9px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    font-family: inherit;
    font-size: 12px;
    color: #4A423B;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}
.md-btn:hover:not(:disabled) { background: #F1E9E0; }
.md-btn:disabled { opacity: .38; cursor: not-allowed; }
.md-btn.md-primary {
    background: #C2855B; color: #fff; font-weight: 500;
}
.md-btn.md-primary:hover:not(:disabled) { background: #B0734A; }
.md-btn.md-danger { color: #C0392B; }
.md-btn.md-danger:hover:not(:disabled) { background: #FBEAE8; }
.md-btn.md-active { background: #EADFD2; color: #8A5A32; }
.md-btn.md-icon { padding: 0 7px; }

/* 下拉菜单 */
.md-menu-wrap { position: relative; display: inline-block; }
.md-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 190px;
    background: #FFFDFA;
    border: 1px solid #EFE8E0;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(45, 41, 38, 0.16);
    padding: 5px;
    display: none;
    z-index: 30;
}
.md-menu.show { display: block; }
.md-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 12.5px;
    color: #3B342E;
    text-align: left;
    border-radius: 7px;
    cursor: pointer;
}
.md-menu-item:hover { background: #F7F1E9; }
.md-menu-sep { height: 1px; background: #EFE8E0; margin: 4px 2px; }
.md-menu-title {
    font-size: 11px;
    color: #A79E95;
    padding: 5px 10px 3px;
}
.md-size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 3px 6px 6px;
}
.md-size-cell {
    border: 1px solid #E7DFD6;
    background: #FDFAF6;
    border-radius: 6px;
    padding: 4px 0;
    font-family: inherit;
    font-size: 12px;
    color: #4A423B;
    cursor: pointer;
}
.md-size-cell:hover { background: #C2855B; color: #fff; border-color: #C2855B; }

/* ---------- 正文区 ---------- */
.md-body {
    flex: 1;
    overflow: auto;
    padding: 26px 34px 60px;
    background: #FFFDFA;
    scroll-behavior: smooth;
}
.md-doc { max-width: 100%; }

/* 文字段落 */
.md-p {
    min-height: 26px;
    padding: 4px 6px;
    margin: 2px 0;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.75;
    color: #2D2926;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    outline: none;
    border: 1px solid transparent;
    font-family: inherit;
}
.md-p:empty::before {
    content: attr(data-ph);
    color: #B9B0A7;
    pointer-events: none;
}
.md-p:focus { border-color: #EAD9C6; background: #FFFCF8; }
.md-p:hover:not(:focus) { background: #FDFAF6; }

/* 表格块 */
.md-block { position: relative; margin: 10px 0; }
.md-block-hint {
    font-size: 11px;
    color: #A79E95;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.md-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 8px;
    /* 预留内边距，避免列宽/行高拖拽手柄（超出单元格 3px）被 overflow 裁掉 */
    padding: 0 6px 8px 0;
}
.md-table {
    border-collapse: collapse;
    border-spacing: 0;
    width: 100%;
    min-width: 320px;
    font-size: 13.5px;
    color: #2D2926;
    background: #fff;
}
.md-table.fixed { table-layout: fixed; }
.md-table td, .md-table th {
    position: relative;
    border: 1px solid #DCD3C8;
    padding: 7px 9px;
    vertical-align: middle;
    text-align: left;
    font-weight: 400;
    min-width: 60px;
    max-width: 520px;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.6;
    outline: none;
}
.md-table th { background: #FBF7F1; font-weight: 600; }
.md-table.b-none td, .md-table.b-none th { border-color: transparent; }
.md-table.b-outer td, .md-table.b-outer th { border-color: transparent; }
.md-table.b-outer { border: 1px solid #DCD3C8; }
.md-table.b-outer tbody tr:first-child td, .md-table.b-outer thead tr:first-child th { border-top-color: #DCD3C8; }
.md-table.b-dashed td, .md-table.b-dashed th { border-style: dashed; }

.md-table td.md-sel, .md-table th.md-sel {
    box-shadow: inset 0 0 0 2px #C2855B;
    background-color: #FDF4EC;
}
.md-table td:focus, .md-table th:focus { box-shadow: inset 0 0 0 2px #D8A87F; }

/* 拖拽调整手柄 */
.md-col-handle {
    position: absolute;
    top: 0; right: -3px;
    width: 7px; height: 100%;
    cursor: col-resize;
    z-index: 3;
}
.md-col-handle:hover { background: rgba(194, 133, 91, .35); }
.md-row-handle {
    position: absolute;
    left: 0; bottom: -3px;
    height: 7px; width: 100%;
    cursor: row-resize;
    z-index: 3;
}
.md-row-handle:hover { background: rgba(194, 133, 91, .35); }

/* 空表格友好提示 */
.md-empty-hint {
    margin-top: 6px;
    font-size: 11.5px;
    color: #B0734A;
    background: #FDF4EC;
    border: 1px dashed #E7C9AD;
    border-radius: 7px;
    padding: 6px 10px;
}

/* 只读视图 */
.md-view .md-p { padding: 2px 0; border: none !important; background: none !important; }
.md-view .md-table td, .md-view .md-table th { cursor: default; }
.md-view .md-table-wrap { overflow-x: auto; }

/* ---------- 底部 ---------- */
.md-foot {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid #EFE8E0;
    background: #FDFAF6;
}
.md-foot-info { flex: 1; font-size: 11.5px; color: #A79E95; }
.md-foot-info b { color: #7A6E63; font-weight: 600; }
.md-tag-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* ---------- 自定义行列弹窗 ---------- */
.md-mini-overlay {
    position: fixed; inset: 0;
    background: rgba(45, 41, 38, .34);
    z-index: 1500;
    display: flex; align-items: center; justify-content: center;
}
.md-mini {
    width: 360px;
    background: #FFFDFA;
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(45, 41, 38, .22);
    padding: 18px;
    animation: mdPop .18s ease;
}
.md-mini h4 { margin: 0 0 4px; font-size: 15px; color: #2D2926; }
.md-mini p { margin: 0 0 14px; font-size: 12px; color: #9A9088; }
.md-mini-row { display: flex; gap: 12px; margin-bottom: 14px; }
.md-mini-field { flex: 1; }
.md-mini-field label {
    display: block; font-size: 12px; color: #7A6E63; margin-bottom: 5px;
}
.md-mini-field input {
    width: 100%; height: 34px; padding: 0 10px;
    border: 1px solid #EFE8E0; border-radius: 8px;
    background: #FDFAF6; font-family: inherit; font-size: 13px; color: #2D2926;
    outline: none; box-sizing: border-box;
}
.md-mini-field input:focus { border-color: #C2855B; background: #fff; }
.md-mini-actions { display: flex; justify-content: flex-end; gap: 8px; }
.md-mini-err { color: #C0392B; font-size: 12px; min-height: 16px; margin-bottom: 6px; }

/* 小屏适配 */
@media (max-width: 900px) {
    .md-overlay { padding: 0; }
    .md-dialog { width: 100%; height: 100%; border-radius: 0; }
    .md-body { padding: 16px 14px 50px; }
    .md-toolbar { padding: 6px 8px; }
}
