/* ================ GLOBAL RESET & FONTS ================ */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600;700&family=Open+Sans&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body, input, button {
  font-family: 'Open Sans', sans-serif;
}
a {
  text-decoration: none;
  color: inherit;
}

/* ================ HEADER / HERO ================ */
#header-container {
  background: linear-gradient(135deg, #2E8B8B 0%, #20B2AA 100%);
  padding: 1.5rem 2rem;
}
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#header .utd-logo {
  display: block;
  width: 40px;
  height: 40px;
  background: url('../images/logo-white.svg') center/contain no-repeat;
}
#header .lexi-tab {
  font-size: 1.75rem;
  font-weight: 600;
  color: #fff;
}
#header .beta-label {
  display: inline-block;
  margin-left: .5rem;
  background: #FFC107;
  color: #000;
  font-size: .75rem;
  padding: .2rem .5rem;
  border-radius: .25rem;
}

/* ================ NAVBAR-STYLE TOOLBAR ================ */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.25rem;
  color: #fff;
  font-weight: 500;
}
#toolbar-left a,
#toolbar-right a {
  color: #fff;
  padding: .5rem 1rem;
  border-radius: .25rem;
  transition: background .2s;
}
#toolbar-left a:hover,
#toolbar-right a:hover {
  background: rgba(255,255,255,0.2);
}
#toolbar-middle span {
  flex: 1;
  text-align: center;
}

/* ================ LAYOUT WRAPPER ================ */
.sidebar {
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  width: 320px;
  height: calc(100vh - 140px);
  overflow-y: auto;
  padding: 1rem;
  position: relative;
}

/* ================ SEARCH INPUT ================ */
.search-field {
  margin: 1rem 0;
  position: relative;
}
.search-field input.search-input {
  width: 100%;
  padding: 1rem 1.5rem;
  padding-right: 6rem;
  border: none;
  border-radius: 50px;
  font-size: 1rem;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.search-field .autoCompleteList {
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: .25rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  position: absolute;
  z-index: 9999;
}
.search-field .autoCompleteList[style*="display: block"] {
  display: block !important;
}
.search-field .autoCompleteList li {
  padding: .75rem 1rem;
  cursor: pointer;
}
.search-field .autoCompleteList li:hover {
  background: #f0f4f8;
}

/* ================ ITEM LIST ================ */
.drugList {
  list-style: none;
  margin-top: 1rem;
}
.drugList li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 0;
  border-bottom: 1px solid #eee;
}
.drugList li .remove-btn {
  background: transparent;
  border: none;
  color: #dc3545;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ================ ACTIONS (Clear/Analyze) ================ */
.actions {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
}
.actions button {
  flex: 1;
  padding: .75rem 0;
  margin: 0 .25rem;
  border: none;
  border-radius: 50px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.clear-btn {
  background: #6c757d;
  color: #fff;
}
.clear-btn:hover {
  background: #5a6268;
}
.analyze-btn {
  background: #20B2AA;
  color: #fff;
}
.analyze-btn:disabled,
.analyze-btn.analyze-disable {
  opacity: .5;
  cursor: not-allowed;
}
.analyze-btn:not(:disabled):hover {
  background: #17a2a0;
}

/* ================ ANALYZE & RESULTS ================ */
#analyze {
  flex: 1;
  padding: 2rem;
  display: none;
  overflow-y: auto;
}
#analyze.active {
  display: block;
}
.intCountBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.intList {
  list-style: none;
}
.intList li {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  border-radius: .5rem;
  margin-bottom: .75rem;
  background: #f8f9fa;
  cursor: pointer;
  transition: background .2s;
}
.intList li:hover {
  background: #e9ecef;
}

/* Rating badges */
.intRiskRating {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  line-height: 2rem;
  text-align: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  margin-right: 1rem;
}
.ratingA { background: #28a745; }
.ratingB { background: #17a2b8; }
.ratingC { background: #ffc107; }
.ratingD { background: #fd7e14; }
.ratingX { background: #dc3545; }

/* ================ DOCUMENT SCREEN ================ */
#doc {
  flex: 1;
  padding: 2rem;
  display: none;
  overflow-y: auto;
}
#doc.active {
  display: block;
}
#doc .back-link {
  display: inline-block;
  margin-bottom: 1rem;
  font-size: 1rem;
  color: var(--primary-color);
}
#docContents {
  margin-top: 1rem;
  line-height: 1.6;
}

/* ================ RESPONSIVE ================ */
@media (max-width: 992px) {
  .sidebar { width: 100%; height: auto; box-shadow: none; }
  #header-container { text-align: center; }
  #header { flex-direction: column; }
  .actions { flex-direction: column; }
  .actions button { margin: .25rem 0; }
}
/* 1) Ẩn tất cả các màn hình client-side theo mặc định */
.mobile-druglist, .desktop-druglist,
.mobile-search,    .desktop-search,
.mobile-analyze,   .desktop-analyze,
.mobile-document,  .desktop-document {
  display: none !important;
}

/* 2) Hiển thị đúng màn hình dựa vào html#ui-<screen> do $$.ui() thiết lập */
html#ui-druglist .desktop-druglist,
html#ui-druglist .mobile-druglist {
  display: block !important;
}

html#ui-search .desktop-search,
html#ui-search .mobile-search {
  display: block !important;
}

html#ui-analyze .desktop-analyze,
html#ui-analyze .mobile-analyze {
  display: block !important;
}

html#ui-document .desktop-document,
html#ui-document .mobile-document {
  display: block !important;
}

/* 3) Đảm bảo autoCompleteList không bị chèn ẩn nhầm */
.autoCompleteList {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #ccc;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  display: none; /* di_script.js sẽ gọi .show() */
}

/* 4) Cho drugList và intList luôn hiển thị dạng block */
.drugList, .intList {
  display: block !important;
}

/* 5) Tinh chỉnh padding/margin để không đè giao diện */
.search-field,
.druglist-guidance,
.intCountBar {
  margin: 1rem;
}

/* 6) Tinh chỉnh chiều cao sidebar nếu cần */
.sidebar {
  height: calc(100vh - 140px);
  overflow-y: auto;
}
/*----------------------------------
  1) Reset mọi màn hình do di_script.js điều khiển
-----------------------------------*/
.mobile-druglist, .desktop-druglist,
.mobile-search,    .desktop-search,
.mobile-analyze,   .desktop-analyze,
.mobile-document,  .desktop-document {
  display: none !important;
}

/*----------------------------------
  2) Hiển thị đúng màn hình dựa trên id trên <html>
     (di_script.js sẽ gán html#ui-druglist / ui-search / ui-analyze / ui-document)
-----------------------------------*/
html#ui-druglist .desktop-druglist,
html#ui-druglist .mobile-druglist {
  display: block !important;
}

html#ui-search .desktop-search,
html#ui-search .mobile-search {
  display: block !important;
}

html#ui-analyze .desktop-analyze,
html#ui-analyze .mobile-analyze {
  display: block !important;
}

html#ui-document .desktop-document,
html#ui-document .mobile-document {
  display: block !important;
}

/*----------------------------------
  3) Thu gọn header và toolbar
-----------------------------------*/
#header-container {
  background: linear-gradient(135deg, #2E8B8B 0%, #20B2AA 100%);
  padding: .5rem 1rem;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#header-container #header .lexi-tab {
  font-size: 1.25rem;
  color: #fff;
  font-weight: 600;
}
#toolbar {
  margin-top: .5rem;
  font-size: .9rem;
  color: #fff;
}
/* Ẩn các link Edit/Clear/Add/Done gốc */
#toolbar-left a, #toolbar-right a {
  display: none;
}
#toolbar-middle span {
  display: none;
}

/*----------------------------------
  4) Search box & autocomplete
-----------------------------------*/
.search-field {
  position: relative;
  margin: 1rem 0;
}
.search-field .search-input {
  width: 100%;
  padding: .6rem 1rem;
  border: 1px solid #ccc;
  border-radius: .5rem;
  font-size: 1rem;
}
.autoCompleteList {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  max-height: 180px;
  overflow-y: auto;
  z-index: 1000;
  list-style: none;
  margin: 0;
  padding: 0;
  display: none; /* JS sẽ .show() */
}
.autoCompleteList li {
  padding: .5rem;
  cursor: pointer;
}
.autoCompleteList li:hover {
  background: #f0f4f8;
}

/*----------------------------------
  5) Buttons Clear List & Analyze
-----------------------------------*/
.desktop-toolbar .new-list-button,
.desktop-toolbar .analyze-button {
  display: inline-block;
  padding: .5rem 1.2rem;
  border-radius: .5rem;
  font-weight: 600;
  text-decoration: none;
  margin-right: .5rem;
  transition: background .2s;
}
.desktop-toolbar .new-list-button {
  background: #6c757d;
  color: #fff;
}
.desktop-toolbar .new-list-button:hover {
  background: #5a6268;
}
.desktop-toolbar .analyze-button {
  background: #20B2AA;
  color: #fff;
  opacity: .6;
  cursor: not-allowed;
}
.desktop-toolbar .analyze-button:not(.analyze-disable) {
  opacity: 1;
  cursor: pointer;
}
.desktop-toolbar .analyze-button:not(.analyze-disable):hover {
  background: #17a2a0;
}

/*----------------------------------
  6) Sidebar & content layout tinh chỉnh
-----------------------------------*/
.sidebar {
  width: 300px;
  padding: 1rem;
  background: #fff;
  box-shadow: 2px 0 4px rgba(0,0,0,0.1);
  overflow-y: auto;
}
#analyze, .desktop-analyze {
  padding: 1rem;
}
.intCountBar, .intList {
  margin: 1rem 0;
}

/*----------------------------------
  7) Đảm bảo drugList & intList luôn hiển thị khi JS bật chúng
-----------------------------------*/
.drugList, .intList {
  display: block !important;
}

/*----------------------------------
  8) Responsive nhỏ
-----------------------------------*/
@media (max-width: 768px) {
  .sidebar { width: 100%; height: auto; box-shadow: none; }
  #header-container { flex-direction: column; align-items: flex-start; }
}
.di-wrapper {
  display: flex;
  height: calc(100vh - 70px);
}
.sidebar {
  width: 320px;
  min-width: 240px;
  max-width: 400px;
  background: #fff;
  box-shadow: 2px 0 8px rgba(0,0,0,0.05);
  z-index: 2;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #eee;
}
.main-content {
  flex: 1;
  background: #fff;
  padding: 2rem 2.5rem 2rem 2rem;
  overflow-y: auto;
}
.di-wrapper {
  display: flex;
  height: calc(100vh - 70px);
}
.sidebar {
  width: 320px;
  min-width: 240px;
  max-width: 400px;
  background: #fff;
  box-shadow: 2px 0 8px rgba(0,0,0,0.05);
  z-index: 2;
  display: flex !important;
  flex-direction: column;
  border-right: 1px solid #eee;
}
.main-content {
  flex: 1;
  background: #fff;
  padding: 2rem 2.5rem 2rem 2rem;
  overflow-y: auto;
}
.sidebar .search-field {
  position: relative;
}
.sidebar .search-field .autoCompleteList {
  display: none;
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  z-index: 9999;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-radius: .25rem;
  padding: 0;
  margin: 0;
  max-height: 220px;
  overflow-y: auto;
}
.sidebar .search-field .autoCompleteList[style*="display: block"] {
  display: block !important;
}
.removedrug {
  color: #e74c3c;
  font-weight: bold;
  margin-right: 5px;
  cursor: pointer;
  font-size: 18px;
  text-decoration: none;
}
.removedrug:hover {
  color: #c0392b;
}
.risk-bar {
    margin: 24px 0 12px 0;
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 17px;
    font-weight: 500;
    background: #f5faff;
    border-radius: 10px;
    padding: 12px 24px 10px 18px;
    box-shadow: 0 2px 8px rgba(24,80,200,0.04);
}
.risk-label {
    display: inline-block;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    text-align: center;
    line-height: 32px;
    font-size: 21px;
    color: #fff;
    font-weight: bold;
    margin-right: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.ratingX { background: #e53935; }
.ratingD { background: #fb8c00; }
.ratingC { background: #fbc02d; color: #222; }
.ratingB { background: #0097a7; }
.ratingA { background: #43a047; }

.risk-more {
    margin-left: 18px;
    color: #333;
    font-style: italic;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 3px;
    transition: color 0.2s;
}
.risk-more:hover {
    color: #2356c8;
}
.risk-more .risk-arrow {
    font-size: 19px;
    margin-left: 2px;
}

.risk-details-panel {
    position: absolute;
    top: 150px; /* điều chỉnh tuỳ header */
    left: 380px; /* điều chỉnh theo sidebar width */
    min-width: 480px;
    background: #fff;
    box-shadow: 0 6px 28px rgba(0,0,0,0.16);
    border-radius: 14px;
    z-index: 2000;
    padding: 22px 32px 14px 32px;
    font-size: 16px;
    animation: fadeIn .22s;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px);}
    to { opacity: 1; transform: none;}
}
.risk-detail-row {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 15px;
}
.risk-detail-row .risk-label {
    width: 38px;
    height: 38px;
    font-size: 22px;
    line-height: 38px;
    margin-right: 0;
}
.risk-detail-row b {
    min-width: 170px;
    display: inline-block;
    margin-top: 4px;
}
.risk-detail-row p {
    margin: 0 0 0 12px;
    color: #333;
    font-size: 15px;
}
#risk-close {
    color: #888;
    font-size: 22px;
    cursor: pointer;
    border-radius: 100px;
    transition: background 0.18s;
}
#risk-close:hover {
    background: #eee;
    color: #d00;
}
