/*
 * Lớp giao diện chung, nạp SAU style.min.css.
 * Viết bằng CSS thuần (không qua Sass) nên sửa trực tiếp ở đây, nhớ tăng ?ver= trong view.
 * Lưu ý: không đặt "display" cho các phần tử được ẩn/hiện bằng .hide, .hidden hoặc jQuery.
 */
:root {
    --primary: #0077bd;
    --primary-dark: #00629c;
    --primary-soft: #e8f4fc;
    --bg: #f3f5f8;
    --surface: #fff;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #e3e8ee;
    --green: #1a8754;
    --green-soft: #e6f5ee;
    --red: #cf3b3b;
    --red-soft: #fdeeee;
    --accent: #8b2fc9;
    --accent-soft: #f6ebfd;
    --radius: 10px;
    /* Bề rộng chung cho thanh đầu trang và nội dung mọi trang */
    --page: 1000px;
    --gutter: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

html,
body {
    background-color: var(--bg);
}

html {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    color: var(--text);
    font-size: 15px;
    letter-spacing: normal;
}

a {
    color: var(--primary);
}

/* ============================ HEADER ============================ */
#header {
    top: 0;
    left: 0;
    align-items: center;
    height: 50px;
    padding: 0 max(var(--gutter), calc((100% - var(--page)) / 2));
    box-sizing: border-box;
    background-color: var(--primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}

#header #logo {
    flex-shrink: 0;
    line-height: 0;
}

#header #logo svg {
    top: 0;
    width: 36px;
    height: 36px;
}

#header #search_nav {
    flex: 1;
    width: auto;
    height: 36px;
    margin: 0 10px;
}

#header .header_search {
    height: 36px;
    border-radius: 8px;
    box-shadow: none;
    overflow: hidden;
    background: #fff;
}

#header #search_input {
    flex: 1;
    min-width: 0;
    width: auto;
    padding: 0 12px;
    outline: none;
}

#header .header_search button {
    width: 40px;
    background: #fff;
    border-radius: 0;
}

#header #nav {
    top: 42px;
    border-radius: 8px;
}

/* Kết quả tìm từ */
#header #nav {
    padding: 4px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .16);
}

#header #js_search_result {
    width: 100%;
}

#header #js_search_result li {
    margin: 0;
    padding: 8px 10px;
    border-bottom: 1px solid #f0f2f5;
    line-height: 1.4;
}

#header #js_search_result li:last-child {
    border-bottom: 0;
}

#header #js_search_result button {
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

#header .user {
    flex-shrink: 0;
    width: auto;
    height: 36px;
    gap: 6px;
    margin: 0;
    padding: 0 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    box-sizing: border-box;
}

#header .user > svg:first-of-type {
    width: 26px;
    height: 26px;
}

#header .panel-user {
    top: 43px;
    right: max(var(--gutter), calc((100% - var(--page)) / 2));
    width: 200px;
    height: auto;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .16);
    cursor: default;
}

#header .panel-user > b {
    display: block;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ============================ KHUNG TRANG ============================ */
#header ~ main {
    top: 0;
    width: calc(100% - 2 * var(--gutter));
    max-width: var(--page);
    min-height: 0;
    margin: 62px auto 32px;
    padding: 0;
    background: transparent;
    box-sizing: border-box;
}

#header ~ main.panel {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    font-size: 15px;
}

#header ~ main [hidden] {
    display: none !important;
}

#header ~ main h1 {
    margin: 0 0 10px;
    font-size: 20px;
}

#header ~ main h2 {
    margin: 0 0 10px;
    font-size: 16px;
}

#header ~ main hr {
    border: 0;
    border-top: 1px solid var(--border);
}

/* Ô nhập liệu */
#header ~ main input[type="text"],
#header ~ main input[type="number"],
#header ~ main input[type="password"],
#header ~ main input[type="email"],
#header ~ main textarea,
#header ~ main select {
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid #cfd6de;
    border-radius: 8px;
    background-color: #fff;
    box-sizing: border-box;
    font-size: 16px;
    line-height: 1.4;
}

#header ~ main textarea {
    resize: vertical;
}

#header ~ main input:focus,
#header ~ main textarea:focus,
#header ~ main select:focus {
    outline: 3px solid rgba(0, 119, 189, .18);
    outline-offset: 0;
}

#header ~ main input:disabled {
    background-color: #f1f3f6;
}

#header ~ main label {
    color: var(--muted);
}

/* Nút bấm */
#header ~ main button,
#header ~ main input[type="submit"] {
    padding: 6px 12px;
    border: 1px solid #cfd6de;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    line-height: 1.3;
    cursor: pointer;
}

#header ~ main button:hover:not(:disabled),
#header ~ main input[type="submit"]:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

#header ~ main button:disabled,
#header ~ main input[type="submit"]:disabled {
    opacity: .55;
    cursor: default;
}

#header ~ main button.btn_primary,
#header ~ main button.qp_grade,
#header ~ main button.context_save,
#header ~ main #js_submit_sentence,
#header ~ main input[type="submit"] {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

#header ~ main button.btn_primary:hover:not(:disabled),
#header ~ main button.qp_grade:hover:not(:disabled),
#header ~ main button.context_save:hover:not(:disabled),
#header ~ main #js_submit_sentence:hover:not(:disabled),
#header ~ main input[type="submit"]:hover:not(:disabled) {
    background: var(--primary-dark);
    color: #fff;
}

#header ~ main #confirmDelete,
#header ~ main #js_confirm_delete {
    border-color: #f1c4c4;
    color: var(--red);
}

#header ~ main #confirmDelete:hover,
#header ~ main #js_confirm_delete:hover {
    border-color: var(--red);
    background: var(--red-soft);
    color: var(--red);
}

/* ============================ TRANG CHỦ ============================ */
#home .home_head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 12px;
}

#header ~ main#home .home_head h1 {
    margin: 0;
}

#home .badge {
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 600;
}

#home .card {
    min-width: 0;
    margin-bottom: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

#home .home_grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 0 12px;
    align-items: stretch;
}

/* Mục tiêu hôm nay */
#home .goal {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 3px 10px;
    align-items: center;
    padding: 7px 0;
}

#home .goal a {
    color: var(--text);
    font-weight: 500;
}

#home .goal a:hover {
    color: var(--primary);
}

#home .goal_count {
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

#home .goal_bar {
    grid-column: 1 / -1;
    height: 5px;
    border-radius: 999px;
    background: #edf0f4;
    overflow: hidden;
}

#home .goal_bar i {
    display: block;
    height: 100%;
    background: var(--primary);
}

#home .goal.is_done .goal_count {
    color: var(--green);
    font-weight: 700;
}

#home .goal.is_done .goal_bar i {
    background: var(--green);
}

#home .extra_link {
    display: inline-block;
    margin-top: 8px;
    font-size: 13px;
}

/* Thiết lập mục tiêu */
#home .settings_form {
    display: grid;
    grid-template-columns: 1fr 96px;
    gap: 8px 12px;
    align-items: center;
}

#home .settings_form label {
    margin: 0;
    color: var(--text);
    text-transform: none;
}

#header ~ main#home .settings_form input[type="number"] {
    width: 100%;
}

#header ~ main#home .settings_form button {
    grid-column: 1 / -1;
    margin-top: 4px;
    padding: 9px;
}

/* Luyện câu nhanh */
#quick_prac .qp_intro {
    margin-bottom: 12px;
    color: var(--muted);
}

#header ~ main #quick_prac .qp_start {
    padding: 9px 20px;
    font-size: 15px;
}

#quick_prac .qp_status {
    margin-bottom: 8px;
    color: var(--muted);
}

#quick_prac .qp_vi {
    margin-bottom: 4px;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.45;
}

#quick_prac .qp_keyword {
    color: var(--primary);
    font-size: 13px;
    font-style: italic;
}

#header ~ main #quick_prac .qp_answer {
    display: block;
    width: 100%;
    margin: 8px 0;
}

#quick_prac .qp_actions {
    display: flex;
    gap: 8px;
}

#quick_prac .qp_result {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f7f9fb;
    line-height: 1.5;
}

#quick_prac .qp_result p {
    margin: 0 0 6px;
}

#quick_prac .qp_result p:last-of-type {
    margin: 8px 0;
}

#quick_prac .qp_score {
    font-weight: 700;
}

/* Danh sách */
#home details.card {
    padding-top: 0;
    padding-bottom: 0;
}

#home details.card summary {
    margin: 0;
    padding: 12px 0;
    font-size: 15px;
}

#home details.card[open] {
    padding-bottom: 12px;
}

#home .scroll_box {
    max-height: 320px;
    overflow: auto;
}

#home .card_head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

#header ~ main#home .card_head h2 {
    margin: 0;
}

#header ~ main#home .btn_copy {
    padding: 3px;
    border: 0;
    background: transparent;
    color: var(--muted);
    line-height: 0;
}

#home .word_text {
    line-height: 1.7;
}

#home table {
    width: 100%;
    border-collapse: collapse;
}

#home .table_home tr:nth-child(2n),
#home .list_word_30 tr:nth-child(2n) {
    background: #f7f9fb;
}

#home .table_home td,
#home .list_word_30 th {
    padding: 5px 8px;
    vertical-align: top;
    line-height: 1.45;
}

#home .table_home td.type_cell {
    width: 84px;
    color: var(--muted);
    font-size: 13px;
}

#home .list_sentence_new li {
    padding: 5px 0;
    border-bottom: 1px solid #f0f2f5;
}

#home .list_sentence_new li:last-child {
    border-bottom: 0;
}

#home .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#home .chips a {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text);
}

#home .chips a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ============================ ÔN TỪ VỰNG ============================ */
#word_practice #tab_prac {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    padding: 4px;
    border-radius: var(--radius);
    background: #eef1f5;
}

#word_practice #tab_prac div {
    flex: 1;
    padding: 7px 6px;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
}

#word_practice #tab_prac div:hover {
    background: #fff;
    color: inherit;
}

#word_practice #tab_prac .tab_checked,
#word_practice #tab_prac .tab_checked:hover {
    background: #fff;
    box-shadow: var(--shadow);
}

#word_practice #tab_prac a {
    display: block;
    color: var(--text);
}

#word_practice #tab_prac .tab_checked a {
    color: var(--accent);
}

#word_practice #tab_prac hr {
    display: none;
}

#show_prac > li {
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

#show_prac > li:last-child {
    border-bottom: 0;
}

#show_prac .mean {
    margin: 0 0 8px;
    line-height: 1.5;
}

#show_prac .usage {
    color: var(--primary);
}

#show_prac .ipa {
    color: #d9600f;
}

#header ~ main#word_practice #show_prac input[type="text"] {
    width: calc(100% - 40px);
    margin-bottom: 8px;
    font-size: 17px;
}

#header ~ main#word_practice #show_prac input[type="text"][style*="border-color"] {
    border-width: 2px;
}

#word_practice .like-btn {
    margin-left: 4px;
    padding: 7px 9px;
    border-radius: 8px;
    background: #eef1f5;
}

#show_prac .hint {
    margin: 0 4px 0 0;
}

#show_prac .openai {
    margin-right: 4px;
}

#show_prac .openai_content,
#show_prac .openai_sentences_exam_content {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--primary-soft);
    line-height: 1.6;
    white-space: pre-line;
}

#show_prac .audio {
    line-height: 0;
    cursor: pointer;
}

#show_prac .audio .ipa {
    line-height: 1.5;
}

#show_prac .openai_sentences_exam {
    margin-top: 8px;
}

.after_test {
    display: none;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}

.after_test.is_tested {
    display: inline-flex;
}

#header ~ main .after_test .context_btn {
    border-color: #dcc2ee;
    color: var(--accent);
}

#header ~ main .after_test .context_btn:hover:not(:disabled) {
    background: var(--accent-soft);
}

.edit_word {
    display: inline-flex;
    padding: 6px;
    border-radius: 8px;
}

.edit_word:hover {
    background: var(--primary-soft);
}

.context_box {
    display: none;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid #dcc2ee;
    border-radius: var(--radius);
    background: #fdfaff;
}

.context_item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    line-height: 1.45;
    cursor: pointer;
}

#header ~ main .context_item {
    color: var(--text);
}

.context_item input {
    width: 16px;
    height: 16px;
    margin: 3px 0 0;
    flex-shrink: 0;
    appearance: auto;
    -webkit-appearance: checkbox;
}

.context_vi {
    display: block;
    color: var(--muted);
}

.context_phrase {
    display: block;
    color: var(--accent);
    font-size: 13px;
    font-style: italic;
}

.context_saved {
    color: var(--green);
    font-size: 13px;
}

.js_try_more {
    gap: 8px;
    margin: 12px 0 0;
}

.js_try_more span {
    padding: 9px 20px;
    border-radius: 8px;
    background: var(--primary);
    font-weight: 600;
}

/* Trạng thái đang tải */
.btn-loading {
    opacity: .7;
    pointer-events: none;
}

.btn-loading .spinner,
.inline-loading .spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 6px;
    border: 2px solid rgba(0, 0, 0, .18);
    border-top-color: rgba(0, 0, 0, .65);
    border-radius: 50%;
    vertical-align: -2px;
    animation: spin .8s linear infinite;
}

.inline-loading {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    opacity: .85;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================ CÂU: THÊM / ÔN / SỬA ============================ */
#sentence_practice #show_sentence_prac > li {
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#sentence_practice .sentence_vi {
    font-weight: 600;
    line-height: 1.45;
}

#header ~ main#sentence_practice input[type="text"] {
    width: 100%;
}

#header ~ main#sentence_practice input[type="text"][style*="border-color"] {
    border-width: 2px;
}

#sentence_practice .result_note {
    border-left-color: var(--primary);
    border-radius: 8px;
    background: #f7f9fb;
}

#sentence_practice .retry_check,
#sentence_practice .show_answers {
    margin: 8px 6px 0 0;
}

#sentence_practice .edit_link {
    margin-left: 0;
}

#sentence_add #js_help {
    margin-bottom: 14px;
    border-radius: 8px;
    background: #f7f9fb;
    line-height: 1.6;
}

#sentence_add .block,
#sentence_edit .block {
    margin-bottom: 16px;
}

#header ~ main#sentence_add input[type="text"],
#header ~ main#sentence_edit input[type="text"],
#header ~ main#sentence_add textarea,
#header ~ main#sentence_edit textarea {
    width: 100%;
}

#sentence_add .true_row,
#sentence_add .false_row {
    border-color: var(--border);
    border-radius: 8px;
}

#sentence_add label.label_false,
#header ~ main .label_false {
    color: var(--red);
}

#header ~ main .label_true {
    color: var(--green);
}

#sentence_edit .list_item {
    border-radius: 8px;
}

#sentence_edit #js_true_list .list_item {
    border-color: #bfe3d0;
    background: #fbfefc;
}

#sentence_edit #js_false_list .list_item {
    border-color: #f3cccc;
    background: #fffbfb;
}

#sentence_edit .add_del {
    align-items: center;
    justify-content: space-between;
    border-top-color: var(--border);
    padding-top: 16px;
}

/* ============================ CHIA ĐỘNG TỪ ============================ */
#prac_verbs .ul_style {
    line-height: 1.55;
}

#prac_verbs > div {
    margin: 0;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

#prac_verbs > div:last-child {
    border-bottom: 0;
}

#prac_verbs .v0 {
    margin-bottom: 6px;
    font-size: 16px;
}

#prac_verbs > div > div {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    align-items: start;
}

#prac_verbs label {
    font-size: 12px;
}

#header ~ main#prac_verbs input[type="text"] {
    width: 100%;
}

#prac_verbs .hint i {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

/* ============================ SỬA TỪ / THÊM TỪ ============================ */
#word_edit form,
#word form {
    width: 100%;
    max-width: none;
    margin-bottom: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    box-sizing: border-box;
}

#word_edit form > div,
#word form > div {
    margin-bottom: 12px;
}

#word_edit form label,
#word form label {
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .4px;
}

#header ~ main#word_edit form input[type="text"],
#header ~ main#word_edit form textarea,
#header ~ main#word form input[type="text"],
#header ~ main#word form select {
    width: 100%;
}

#word_edit #js_examples_result li {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}

#word_edit #title {
    margin: 8px 0;
    font-size: 15px !important;
}

/* Danh sách loại từ / chủ đề: dạng thẻ xếp ngang cho gọn */
#word_edit .list_check {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 132px;
    overflow: auto;
    border: 0;
}

#word_edit .list_check li {
    padding: 4px 11px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
}

#word_edit .list_check li:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

/* Form xoá từ: chỉ có 1 nút, không cần khung */
#word_edit form:not(#form) {
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    text-align: right;
}

/* ============================ ĐĂNG NHẬP / ĐĂNG KÝ ============================ */
body.login_register {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    height: auto;
}

.login_register .log_left {
    display: none;
}

.login_register .log_right {
    flex: 0 1 400px;
    margin: 24px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login_register .log_right .form_input {
    padding: 28px 24px;
}

.login_register .log_right .form_input .form {
    max-width: none;
}

.login_register .log_right .form_input .form .header {
    margin-bottom: 18px;
}

.login_register .log_right .form_input .form input {
    margin-bottom: 12px;
    padding: 11px 12px;
    border-color: #cfd6de;
    border-radius: 8px;
    font-size: 16px;
}

.login_register .log_right .form_input .form input:focus {
    border-color: var(--primary);
}

.login_register .log_right .form_input .sub_link {
    align-items: center;
    gap: 12px;
}

.login_register .log_right .form_input .sub_link .submit_reg {
    width: 45%;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

/* ============================ MÀN HÌNH NHỎ ============================ */
@media screen and (max-width: 600px) {
    :root {
        --gutter: 8px;
    }

    #header ~ main {
        margin-top: 58px;
    }

    #header ~ main.panel {
        padding: 12px;
    }

    #header #logo svg {
        width: 34px;
        height: 34px;
    }

    #header .user {
        padding: 0 6px;
        gap: 4px;
    }

    #header #search_nav {
        margin: 0 6px;
    }

    #home .home_grid {
        grid-template-columns: minmax(0, 1fr);
    }

    #prac_verbs > div > div {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
