/* === RESET & BASE === */
* { box-sizing: border-box; outline: none; }
body {
  font-family: 'Montserrat', sans-serif;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f3f4f6;
  color: #374151;
  overflow: hidden;
}

/* === SCROLLBAR === */
.custom-scrollbar::-webkit-scrollbar { width: 10px; height: 10px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f1f1; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; border: 2px solid #f1f1f1; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* === HEADER === */
.app-header {
  background: white; border-bottom: 1px solid #e5e7eb; padding: 0 20px; height: 60px;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0; z-index: 100;
}
.header-left { flex: 0 0 350px; } 
.header-right { flex: 0 0 50px; display: flex; justify-content: flex-end; }
.header-center { flex: 1; display: flex; justify-content: center; height: 100%; }
.header-left h1 { margin: 0; font-size: 16px; color: #111827; font-weight: 700; margin-bottom: 4px; }

/* DONATE STYLES */
.donate-info { font-size: 11px; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.donate-label {
    background: #dc2626; color: white; padding: 2px 6px; border-radius: 4px;
    font-weight: 800; font-size: 10px; animation: pulse-red 2s infinite;
}
.donate-details { color: #b91c1c; font-weight: 700; font-size: 12px; letter-spacing: 0.5px; }
@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* === TABS === */
.tabs { display: flex; gap: 5px; height: 100%; align-items: flex-end; }
.tab-button {
  border: none; background: transparent; padding: 0 20px; height: 45px;
  cursor: pointer; font-weight: 600; color: #6b7280;
  border-bottom: 3px solid transparent; transition: all 0.2s;
  font-size: 13px; text-transform: uppercase;
}
.tab-button:hover { color: #2563eb; background: #f9fafb; }
.tab-button.active { color: #2563eb; border-bottom-color: #2563eb; background: linear-gradient(to top, #eff6ff, transparent); }

/* === MAIN LAYOUT === */
#app-body { 
    flex: 1; overflow: hidden; position: relative; display: flex; flex-direction: row; 
}
#content-wrapper {
    flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative;
}
.tab-content { display: none; width: 100%; height: 100%; }
.tab-content.active { display: flex; }
.main-layout { flex-direction: column; padding: 15px; background: #f3f4f6; }

.editor-area { 
    flex: 1; display: flex; flex-direction: column; overflow: hidden; 
    border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    background: white;
}

/* === EDITOR & HIGHLIGHT SYNC (V30 GRID SYSTEM) === */
.editor-wrapper { 
    flex: 1; 
    background: white; 
    position: relative; 
    overflow: hidden; 
    border-radius: 8px 8px 0 0;
    /* Grid container để chồng layer chính xác */
    display: grid;
}

.layer-container {
    display: grid;
    grid-template-areas: "editor";
    width: 100%;
    height: 100%;
    overflow: hidden; /* Scrollbar ở element con */
}

/* Shared Styles - TUYỆT ĐỐI GIỐNG NHAU */
.editor-input, .highlight-layer {
    grid-area: editor; /* Chồng lên nhau */
    
    width: 100%; 
    height: 100%;
    
    padding: 20px;
    padding-bottom: 100px;
    margin: 0;
    border: none;
    
    font-family: 'Montserrat', sans-serif;
    font-size: 16px;
    line-height: 1.8;
    letter-spacing: 0px; /* Fix lệch chữ */
    
    font-variant-ligatures: none;
    -webkit-font-feature-settings: "liga" 0;
    font-feature-settings: "liga" 0;
    
    white-space: pre-wrap; 
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    
    /* Buộc hiện thanh cuộn để khớp width text */
    overflow-y: scroll; 
}

/* Layer 1: Highlight */
.highlight-layer {
    z-index: 1; 
    background: white;
    color: #374151;
    pointer-events: none;
}
/* Ẩn thanh cuộn của layer highlight nhưng vẫn giữ khoảng trống của nó */
.highlight-layer::-webkit-scrollbar { width: 10px; background: transparent; }
.highlight-layer::-webkit-scrollbar-thumb { background: transparent; }

/* Layer 2: Input */
.editor-input {
    z-index: 2; 
    background: transparent; 
    color: transparent; 
    
    /* WebKit Trick để render font giống hệt màu thật */
    -webkit-text-fill-color: transparent;
    
    caret-color: #000;
    resize: none;
    outline: none; 
}
/* Thanh cuộn của Input thì hiện bình thường */
.editor-input::-webkit-scrollbar { width: 10px; }
.editor-input::-webkit-scrollbar-track { background: #f1f1f1; }
.editor-input::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; border: 2px solid #f1f1f1; }
.editor-input::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.editor-input::placeholder { -webkit-text-fill-color: #9ca3af; color: #9ca3af; }


/* === HIGHLIGHT STYLES === */
.highlight-layer span {
    border-radius: 3px;
    padding: 0;
    /* In đậm giả bằng bóng để không vỡ layout */
    text-shadow: 0 0 0.6px currentColor;
}

/* Replace & AutoCaps (Nền đặc) */
.hl-yellow { background-color: #fde047; color: #000; } 
.hl-blue { background-color: #93c5fd; color: #000; } 
.hl-orange-dark { background-color: #fb923c; color: #000; } 

/* Keywords (Nền nhạt + Border Bottom + Text Đậm) */
.keyword { 
    font-weight: normal; /* Reset font-weight thật */
    text-shadow: 0 0 0.7px currentColor; /* Đậm hơn xíu */
} 
.hl-pink   { background-color: #fce7f3; color: #000; border-bottom: 2px solid #db2777; }
.hl-green  { background-color: #dcfce7; color: #000; border-bottom: 2px solid #16a34a; }
.hl-orange { background-color: #ffedd5; color: #000; border-bottom: 2px solid #ea580c; }
.hl-purple { background-color: #f3e8ff; color: #000; border-bottom: 2px solid #9333ea; }
.hl-red    { background-color: #fee2e2; color: #000; border-bottom: 2px solid #dc2626; }


/* === FOOTER & UI === */
.editor-footer {
    padding: 10px 15px; border-top: 1px solid #e5e7eb; background: #f9fafb;
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.footer-actions { display: flex; gap: 8px; }
.badge { 
  background: #1abc9c; color: white; padding: 3px 10px; border-radius: 12px; 
  font-size: 11px; font-weight: 600; box-shadow: 0 2px 4px rgba(26, 188, 156, 0.3);
}

/* === SIDEBAR === */
.sidebar {
    width: 20%; background: white; border-left: 1px solid #e5e7eb;
    display: flex; flex-direction: column; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0; overflow: hidden; z-index: 50;
}
.sidebar.closed { width: 0 !important; border: none; }

.sidebar-header { padding: 12px 15px; background: #f9fafb; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; white-space: nowrap; }
.sidebar-header h3 { margin: 0; font-size: 13px; font-weight: 700; color: #374151; }
.sidebar-content { padding: 15px; flex: 1; overflow-y: auto; }

.sidebar-input { width: 100%; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; outline: none; }
.sidebar-input:focus { border-color: #2563eb; }
.tags-container { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.sidebar-toggle-btn {
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: 4px; cursor: pointer; background: #f3f4f6; border: none; font-size: 18px; color: #6b7280;
}
.sidebar-toggle-btn .icon { pointer-events: none; font-weight: bold; }
.sidebar-toggle-btn:hover { background: #e5e7eb; color: #111827; }

/* === SETTINGS UI === */
.settings-layout { flex-direction: column; background: #f3f4f6; padding: 15px; overflow-y: auto; }
.panel-container { background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); max-width: 1000px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.panel-header { padding: 15px 20px; border-bottom: 1px solid #f3f4f6; display: flex; justify-content: space-between; align-items: center; }
.panel-header h2 { margin: 0; font-size: 16px; color: #111827; font-weight: 700; }

.mode-actions { display: flex; gap: 8px; align-items: center; }
.select-wrapper { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-right: 10px; }
#mode-select { padding: 6px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; outline: none; }

.toolbar { padding: 10px 20px; background: #f9fafb; border-bottom: 1px solid #f3f4f6; display: flex; flex-wrap: wrap; gap: 15px; align-items: center; }
.toolbar-group { display: flex; gap: 8px; align-items: center; }
.list-actions { padding: 10px 20px; display: flex; gap: 10px; }
.scroll-area { padding: 10px 20px; background: #f9fafb; min-height: 200px; }

.control-group { display: flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: #555; }
.input-sm { padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 4px; font-size: 13px; outline: none; }
.keywords-panel { padding: 20px; }
.keywords-input-area { width: 100%; }
.input-group { display: flex; gap: 10px; align-items: center; }
.w-full-input { flex: 1; padding: 8px; border: 1px solid #d1d5db; border-radius: 4px; outline: none; box-sizing: border-box; }
.w-full-input:focus { border-color: #10b981; }
.input-label { font-size: 13px; font-weight: 700; color: #374151; margin: 0 0 8px 0; }

.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 12px; font-weight: 600; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #10b981; color: white; }
.btn-success:hover { background: #059669; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: #f59e0b; color: white; }
.btn-warning:hover { background: #c2410c; }
.btn-outline { background: white; border: 1px solid #d1d5db; color: #374151; }
.btn-outline:hover { border-color: #9ca3af; background: #f9fafb; }
.icon-btn { min-width: 120px; }

.btn-toggle { background: #e5e7eb; color: #6b7280; padding: 8px 15px; border-radius: 6px; font-size: 12px; font-weight: 700; border: 1px solid transparent; }
.btn-toggle:hover { background: #d1d5db; color: #374151; }
.btn-toggle.active { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }

.btn-teal { background: #ccfbf1; color: #0f766e; padding: 8px 15px; border-radius: 6px; font-size: 12px; font-weight: 700; border: 1px solid #5eead4; }
.btn-teal:hover { background: #99f6e4; }

.btn-action { background: #f3e8ff; color: #6b21a8; padding: 8px 15px; border-radius: 6px; font-size: 12px; font-weight: 700; border: 1px solid #d8b4fe; }
.btn-action:hover { background: #e9d5ff; color: #581c87; border-color: #c084fc; }

.btn-blue-toolbar { background: #dbeafe; color: #1e40af; padding: 8px 15px; border-radius: 6px; font-size: 16px; font-weight: 700; border: 1px solid #93c5fd; width: 45px; }
.btn-blue-toolbar:hover { background: #bfdbfe; }
.btn-red-toolbar { background: #fee2e2; color: #991b1b; padding: 8px 15px; border-radius: 6px; font-size: 14px; font-weight: 700; border: 1px solid #fca5a5; width: 45px; }
.btn-red-toolbar:hover { background: #fecaca; }

.pair-row { display: grid; grid-template-columns: 0.5fr 0.5fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px dotted #e5e7eb; align-items: center; }
.pair-row:last-child { border-bottom: none; }
.pair-input { flex: 1; padding: 8px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; }
.delete-btn { background-color: #fca5a5; color: #dc2626; border: none; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-weight: 600; }
.delete-btn:hover { background-color: #f87171; }
.empty-message { text-align: center; color: #9ca3af; padding: 20px; font-size: 13px; }

.tag { background: #eff6ff; color: #1e40af; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; border: 1px solid #93c5fd; }
.tag .remove-tag { cursor: pointer; width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.tag .remove-tag:hover { background: #dbeafe; color: red; }

#notification-container { position: fixed; top: 70px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.notification { padding: 12px 20px; border-radius: 6px; color: white; font-size: 13px; font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,0.2); animation: slideIn 0.3s ease-out; display: flex; align-items: center; }
.notification.success { background: #10b981; border-left: 4px solid #047857; }
.notification.error { background: #ef4444; border-left: 4px solid #7f1d1d; }
.notification.warning { background: #f59e0b; border-left: 4px solid #d97706; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: 0; opacity: 1; } }
.hidden { display: none !important; }
