/**
 * TQC Layout Styles — Sidebar, header, content area, auth layout.
 */

/* --- App Layout --- */
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  height: 65px;
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-light);
  position: sticky;
  top: 0;
  z-index: 200;
  gap: var(--space-4);
}

.header__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.header__toggle {
  display: none;
  background: none;
  border: none;
  padding: var(--space-2);
  cursor: pointer;
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
}

.header__toggle:hover {
  background: var(--color-bg);
}

.header__logo {
  height: 45px;
  width: auto;
}

.header__brand-text {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

.header__right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
  margin-left: auto;
}

/* --- Header Actions (lang, notifs) --- */
.header-action {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: var(--space-1);
}

.header-action:hover {
  color: var(--color-text);
}

.header-action__flag {
  width: 20px;
  height: 15px;
  border-radius: 2px;
  flex-shrink: 0;
}

.header-action__label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.header-action__badge {
  position: absolute;
  right: -5px;
  top: -6px;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: 700;
  background: var(--color-notification);
  color: var(--color-white);
  border-radius: 50px;
  line-height: 1;
}

/* --- Notification Dropdown --- */
.notif-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: -8px;
  width: 340px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 300;
  overflow: hidden;
}

.notif-dropdown--open {
  display: flex;
  flex-direction: column;
}

.notif-dropdown__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
}

.notif-dropdown__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

.notif-dropdown__mark-all {
  font-size: var(--font-size-xs);
  color: var(--color-primary);
  cursor: pointer;
  text-decoration: none;
}

.notif-dropdown__mark-all:hover {
  text-decoration: underline;
}

.notif-dropdown__list {
  max-height: 360px;
  overflow-y: auto;
}

.notif-dropdown__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background 0.15s;
}

.notif-dropdown__item:last-child {
  border-bottom: none;
}

.notif-dropdown__item:hover {
  background: var(--color-bg);
}

.notif-dropdown__item--unread {
  background: rgba(var(--color-primary-rgb, 63, 81, 181), 0.04);
  border-left: 3px solid var(--color-primary);
}

.notif-dropdown__msg {
  font-size: var(--font-size-sm);
  color: var(--color-text);
  line-height: 1.4;
}

.notif-dropdown__item--unread .notif-dropdown__msg {
  font-weight: var(--font-weight-medium);
}

.notif-dropdown__time {
  font-size: 11px;
  color: var(--color-text-muted);
}

.notif-dropdown__empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* --- Header Profile --- */
.header-profile {
  position: relative;
  cursor: pointer;
}

.header-profile__info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.header-profile__name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  line-height: 1.2;
}

.header-profile__role {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  gap: 2px;
}

.header-profile__dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  padding: var(--space-2);
  z-index: 300;
}

.header-profile__dropdown--open {
  display: block;
}

.header-profile__dropdown--from-bottom {
  position: fixed;
  bottom: 88px;
  right: var(--space-3);
  top: auto;
  min-width: 200px;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
}

.header-profile__header {
  display: none;
}

.header-profile__dropdown--from-bottom .header-profile__header {
  display: flex;
  flex-direction: column;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: var(--space-2);
}

.header-profile__header-name {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.header-profile__header-role {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.header-profile__dropdown--from-bottom .header-profile__item {
  font-size: var(--font-size-base);
  padding: var(--space-3) var(--space-4);
  gap: var(--space-3);
}

.header-profile__dropdown--from-bottom .header-profile__item svg {
  width: 20px;
  height: 20px;
}

.header-profile__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  text-decoration: none;
  cursor: pointer;
}

.header-profile__item:hover {
  background: var(--color-bg);
}

/* --- Header Navigation (desktop horizontal) --- */
.header__nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-nav-item {
  position: relative;
}

.header-nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-normal);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.header-nav-link:hover {
  color: var(--color-primary);
}

.header-nav-link--active {
  color: var(--color-primary);
}

.header-nav-link--active .header-nav-link__icon {
  filter: brightness(0) saturate(100%) invert(33%) sepia(93%) saturate(1764%) hue-rotate(222deg) brightness(96%) contrast(93%);
}

.header-nav-link__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.header-nav-link__badge {
  position: absolute;
  top: -2px;
  right: -4px;
  padding: 2px 5px;
  font-size: 10px;
  font-weight: 700;
  background: var(--color-notification);
  color: var(--color-white);
  border-radius: 50px;
  line-height: 1;
  min-width: 16px;
  text-align: center;
}

.header-nav-chevron {
  color: var(--color-text);
  width: 12px;
  height: 12px;
  transition: transform 0.5s ease;
  flex-shrink: 0;
}

.header-nav-item:hover > .header-nav-link .header-nav-chevron {
  transform: rotate(90deg);
}

/* Dropdown submenus */
.header-nav-dropdown {
  display: none;
  flex-direction: column;
  position: absolute;
  top: 30px;
  left: 0;
  background: var(--color-white);
  border: 1px solid var(--color-primary);
  width: max-content;
  padding: 10px;
  border-radius: 10px;
  z-index: 300;
}

.header-nav-item:hover > .header-nav-dropdown {
  display: flex;
  z-index: 200;
}

.header-nav-dropdown__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 15px;
  border-radius: 10px;
  color: var(--color-text);
  font-size: var(--font-size-sm);
  text-decoration: none;
  cursor: pointer;
}

.header-nav-dropdown__link:hover {
  background: var(--color-primary-light);
}

.header-nav-dropdown__icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.header-nav-dropdown__sub {
  position: relative;
}

.header-nav-dropdown__link--parent {
  justify-content: space-between;
}

.header-nav-dropdown__label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-nav-dropdown__chevron {
  flex-shrink: 0;
  margin-left: 8px;
}

.header-nav-dropdown__flyout {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  background: var(--color-white);
  border: 1px solid var(--color-primary);
  border-radius: 10px;
  padding: 10px;
  width: max-content;
  min-width: 160px;
  z-index: 310;
}

.header-nav-dropdown__sub:hover > .header-nav-dropdown__flyout {
  display: flex;
  flex-direction: column;
}

/* --- Sidebar (mobile only) --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border-light);
  overflow: visible;
  z-index: 1000;
  transform: translateX(0);
  transition: transform var(--transition-base);
  display: flex;
  flex-direction: column;
}

.sidebar--closed {
  transform: translateX(-100%);
}

.sidebar__nav {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-1);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
}

.sidebar-overlay--visible {
  display: block;
}

/* --- Sidebar Navigation (tile grid) --- */
.nav-item {
  position: relative;
}

.nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  text-align: center;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.nav-link--active {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

.nav-link__icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.nav-link__text {
  line-height: 1.2;
}

.nav-chevron {
  position: absolute;
  top: 50%;
  right: var(--space-2);
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  transition: transform var(--transition-fast);
}

.nav-item--open > .nav-link .nav-chevron {
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
}

.nav-submenu {
  display: none;
  position: absolute;
  left: 100%;
  top: 0;
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg, 0 4px 12px rgba(0,0,0,0.15));
  padding: var(--space-2);
  z-index: 1001;
}

.nav-item--open > .nav-submenu {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-submenu .nav-link {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  font-size: var(--font-size-sm);
  padding: var(--space-2) var(--space-3);
  gap: var(--space-2);
  text-align: left;
  text-decoration: none;
  border: none;
  border-bottom: none;
}

.nav-submenu .nav-link__icon {
  width: 24px;
  height: 24px;
}

/* --- Content --- */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-2);
  width: 100%;
}

.content > .card {
  flex: 1;
}

/* --- Footer --- */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-light);
}

.footer a {
  display: inline-flex;
  align-items: center;
}

.footer__logo {
  height: 30px;
  width: auto;
}

/* --- Auth Layout --- */
.auth-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-white);
  padding: var(--space-4);
}

.auth-layout__wrapper {
  width: 100%;
  max-width: 440px;
}

.auth-layout__brand {
  text-align: center;
  margin-bottom: var(--space-6);
}

.auth-layout__logo {
  height: 60px;
  width: auto;
}

.auth-layout__card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  padding: var(--space-8) var(--space-10);
  width: 100%;
}

.auth-layout__title {
  font-size: var(--font-size-xl);
  color: var(--color-text);
  margin: 0;
}

.auth-layout__portal-title {
  font-size: 1.75rem;
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin: 0 0 var(--space-1) 0;
  text-align: center;
}

.auth-layout__subtitle {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  margin: 0;
}

/* --- Toast --- */
#tqc-toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.tqc-toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  box-shadow: var(--shadow-lg);
  transform: translateX(120%);
  transition: transform var(--transition-base);
  max-width: 400px;
}

.tqc-toast--visible {
  transform: translateX(0);
}

.tqc-toast--success { background: var(--color-success); color: var(--color-white); }
.tqc-toast--error   { background: var(--color-danger);  color: var(--color-white); }
.tqc-toast--warning { background: var(--color-warning); color: var(--color-text); }
.tqc-toast--info    { background: var(--color-info);    color: var(--color-white); }

/* --- Dialog --- */
dialog {
  margin: auto;
}

.tqc-dialog {
  border: none;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: 420px;
  width: 90%;
}

.tqc-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.tqc-dialog__content {
  padding: var(--space-6);
}

.tqc-dialog__title {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-2);
}

.tqc-dialog__message {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-6);
}

.tqc-dialog__actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* --- Modal --- */
.tqc-modal { max-width: 90vw; }
.tqc-modal--sm { width: 400px; }
.tqc-modal--md { width: 600px; }
.tqc-modal--lg { width: 800px; }

.tqc-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.tqc-modal__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin: 0;
}

.tqc-modal__close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  padding: 0 var(--space-1);
  line-height: 1;
}
.tqc-modal__close:hover { color: var(--color-text); }

.tqc-modal__body { max-height: 60vh; overflow-y: auto; }

/* --- Collapsible table rows --- */
.bs-hidden { display: none !important; }

/* --- Mobile Bottom Nav --- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-light);
  z-index: 200;
  align-items: center;
  justify-content: space-around;
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-1) var(--space-2);
  font-size: 11px;
  font-family: var(--font-family);
  color: var(--color-text-secondary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
}

.bottom-nav__item:hover,
.bottom-nav__item--active {
  color: var(--color-primary);
}

/* --- Responsive --- */
@media (max-width: 1160px) {
  .header__nav {
    display: none;
  }

  .header {
    height: 80px;
  }

  .header__logo {
    height: 56px;
  }

  .bottom-nav {
    display: flex;
    height: 80px;
  }

  .bottom-nav__item {
    font-size: var(--font-size-sm);
    padding: var(--space-2) var(--space-3);
  }

  .bottom-nav__item svg,
  .bottom-nav__item img {
    width: 40px;
    height: 40px;
  }

  .bottom-nav__item img,
  .nav-link__icon {
    filter: invert(54%) sepia(10%) saturate(520%) hue-rotate(176deg) brightness(92%) contrast(87%);
  }

  body {
    padding-bottom: 80px;
  }

  .header-profile__info {
    display: none;
  }

  .header-action svg {
    width: 40px;
    height: 40px;
  }

  .header-action {
    padding: var(--space-2);
  }

  .header-action__badge {
    right: 0;
    top: 0;
    font-size: 12px;
    padding: 3px 6px;
  }

  .content {
    padding: var(--space-4);
  }

  .auth-layout__card {
    padding: var(--space-6);
  }

  /* Hide table, show mobile cards */
  .table-wrapper > table.table { display: none; }
  .mobile-cards { display: flex !important; }
}

/* --- Mobile Cards (table alternative) --- */
.mobile-cards {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.mobile-cards__empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) 0;
}

.mobile-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
}

.mobile-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: var(--space-2);
}

.mobile-card__title {
  font-weight: 600;
  font-size: var(--font-size-base);
  color: var(--color-text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-card__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.mobile-card__actions .btn--icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
  background: var(--color-bg);
}

.mobile-card__actions .btn--icon svg {
  width: 18px;
  height: 18px;
}

.mobile-card__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mobile-card__field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-1) 0;
  min-height: 28px;
}

.mobile-card__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  flex-shrink: 0;
  margin-right: var(--space-3);
}

.mobile-card__value {
  font-size: var(--font-size-sm);
  color: var(--color-text);
  text-align: right;
  word-break: break-word;
}
