:root {
    --primary: #4f46e5;
    --primary-light: #eef2ff;
    --secondary: #64748b;
    --success: #10b981;
    --purple: #8b5cf6;
    --warning: #f59e0b;
    --bg-body: #f1f5f9;
    --surface: #ffffff;
    --border: #cbd5e1;
    --text-main: #0f172a;
    --text-light: #64748b;
    --radius: 10px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    
    /* Configurable Variables */
    --editor-font-size: 16px;
    --editor-font-family: 'Nunito', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }
body { font-family: 'Nunito', sans-serif; background: var(--bg-body); color: var(--text-main); height: 100vh; overflow: hidden; font-size: 15px; }

/* LAYOUT */
.app-container { display: flex; height: 100%; }
.sidebar { width: 260px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 15px; z-index: 20; }
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.tab-content { padding: 20px; height: 100%; overflow-y: auto; display: flex; flex-direction: column; }
.full-height-tab { padding: 10px; padding-bottom: 0; }
.hidden { display: none !important; }

/* SIDEBAR */
.logo-area { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; color: var(--primary); margin-bottom: 20px; padding-left: 5px; }
.logo-icon { width: 32px; height: 32px; background: var(--primary-light); color: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.current-story-card { background: linear-gradient(135deg, #4f46e5, #6366f1); padding: 15px; border-radius: var(--radius); color: white; margin-bottom: 20px; box-shadow: var(--shadow); }
.story-name { font-weight: 700; margin: 5px 0 10px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item { padding: 10px 15px; width: 100%; text-align: left; background: transparent; border: none; color: var(--text-light); font-weight: 600; cursor: pointer; border-radius: 8px; margin-bottom: 4px; display: flex; align-items: center; gap: 10px; transition: 0.2s; font-size: 15px; }
.nav-item:hover { background: #f8fafc; color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item.highlight-btn { color: var(--primary); border: 1px dashed var(--primary); background: #f5f3ff; margin-top: 10px; }
.nav-label { font-size: 11px; font-weight: 800; color: #94a3b8; margin: 15px 0 5px 10px; letter-spacing: 0.5px; }

/* TOP BAR */
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding-bottom: 5px; min-height: 50px; }
.top-bar.tight-header { margin-top: -5px; }
.header-info h2 { font-size: 22px; font-weight: 800; color: var(--text-main); margin-bottom: 2px; }
.sub-header { font-size: 13px; color: var(--text-light); margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; }

/* BUTTONS */
.btn-rounded { padding: 6px 16px; border-radius: 20px; font-weight: 700; font-size: 13px; cursor: pointer; border: none; display: flex; align-items: center; gap: 6px; transition: 0.2s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 5px rgba(79, 70, 229, 0.3); }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { background: rgba(255,255,255,0.2); border:none; color:white; padding: 4px 10px; border-radius: 20px; font-size: 11px; cursor: pointer; }

/* GRID */
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; padding-bottom: 20px; }
.story-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; position: relative; transition: all 0.2s; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; min-height: 140px; }
.story-card:hover { transform: translateY(-4px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); border-color: var(--primary); }
.story-card h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-main); }
.story-card p { font-size: 13px; color: var(--text-light); margin-bottom: 15px; flex: 1; line-height: 1.4; }
.story-stats { border-top: 1px solid #f1f5f9; padding-top: 12px; display: flex; gap: 15px; font-size: 12px; font-weight: 600; color: var(--secondary); }
.icon-actions { position: absolute; top: 15px; right: 15px; opacity: 0; transition: 0.2s; }
.story-card:hover .icon-actions { opacity: 1; }

/* TABLE STYLES (BORDER FIX) */
.table-container { background: white; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; box-shadow: var(--shadow); flex: 1; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; }

/* FIX: Border chạy thẳng xuống */
.data-table th { background: #f8fafc; padding: 12px 10px; font-size: 13px; font-weight: 700; color: var(--secondary); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); position: sticky; top: 0; z-index: 10; text-align: center; }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); vertical-align: middle; font-size: 14px; text-align: center; } 

.data-table td:last-child, .data-table th:last-child { border-right: none; }
.data-table tr:hover { background: #fcfcfc; }
.action-cell { display: flex; justify-content: center; gap: 10px; align-items: center; }

/* TAGS */
.tag { padding: 4px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; white-space: nowrap; display: inline-block; }
.tag.character { background: #e0e7ff; color: #4338ca; }
.tag.location { background: #dcfce7; color: #15803d; }
.tag.faction { background: #fee2e2; color: #b91c1c; }
.tag.org { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }
.tag.title { background: #ffedd5; color: #c2410c; }
.tag.item { background: #f1f5f9; color: #475569; }

/* RELATIONS DISPLAY (FIX CROSS LOGIC & FONT SIZE) */
.rel-cell-content { display: flex; flex-direction: column; align-items: center; }
.rel-main-name { font-weight: 700; color: var(--text-main); font-size: 15px; }
.rel-sub-addr { font-size: 14px; color: #334155; margin-top: 4px; font-weight: 600; font-style: normal; } /* To & Rõ hơn */
.rel-arrow { color: var(--purple); font-weight: 700; text-align: center; }

/* EDITOR LAYOUT & FONT */
.editor-actions-bar { display: flex; gap: 10px; margin-bottom: 10px; justify-content: flex-end; }
.editor-layout { display: flex; gap: 15px; height: calc(100% - 50px); padding-bottom: 10px; }
.editor-pane { flex: 1; display: flex; flex-direction: column; background: white; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.pane-header { background: #f8fafc; padding: 8px 15px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; height: 40px; flex-shrink: 0; }
.header-title { font-weight: 700; font-size: 13px; color: var(--secondary); display: flex; align-items: center; gap: 6px; }
.badge-group { display: flex; gap: 8px; }
.badge-pill { padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; border: 1px solid transparent; display: flex; align-items: center; gap: 4px; }
.badge-pill.gray { background: #e2e8f0; color: #475569; }
.badge-pill.yellow { background: #fef3c7; color: #d97706; border-color: #fcd34d; }
.badge-pill.green { background: #dcfce7; color: #166534; border-color: #86efac; }
.badge-pill.purple { background: #f3e8ff; color: #7e22ce; border-color: #d8b4fe; }

/* APPLY VARIABLES TO BOTH INPUT AND OUTPUT */
textarea, #processed-output { flex: 1; border: none; padding: 20px; resize: none; overflow-y: auto; outline: none; width: 100%; height: 100%; line-height: 1.6; font-size: var(--editor-font-size); font-family: var(--editor-font-family); }
.result-pane #processed-output { background: white; }
.hl-found { background: #fef08a; border-bottom: 2px solid #eab308; }
.hl-replaced { background: #bbf7d0; color: #14532d; font-weight: 700; border-bottom: 2px solid #22c55e; }

/* UTILS */
.icon-btn { width: 28px; height: 28px; border-radius: 50%; border: none; background: transparent; color: var(--secondary); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; transition: 0.2s; }
.icon-btn:hover { background: #f1f5f9; color: var(--primary); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(2px); }
.modal-content { background: white; width: 500px; border-radius: 12px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); overflow: hidden; }
.modal-lg { width: 700px; }
.modal-header { padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 16px; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer { padding: 15px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; background: #f8fafc; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 700; font-size: 13px; }
.form-row { display: flex; gap: 15px; }
.relation-row { display: flex; gap: 15px; align-items: flex-end; margin-bottom: 10px; }
.col-main { flex: 2; }
.col-sub { flex: 1; }
.input-with-btn { display: flex; gap: 5px; }
.btn-icon-small { width: 42px; flex-shrink: 0; background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.full-width { width: 100%; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.filter-bar { display: flex; gap: 10px; margin-bottom: 10px; }
.close { cursor: pointer; font-size: 18px; color: var(--text-light); }
.settings-box { max-width: 600px; margin: 0 auto; background: white; padding: 30px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); }
