@import '../common-vars.css';

body {
  font-family: var(--font-family);
  background-color: var(--surface);
  color: var(--on-surface);
  line-height: 1.6;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
}

/* --- Layout --- */
.container {
  display: flex;
  gap: 0;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background-color: var(--surface-container);
  padding: var(--spacing-6);
  height: 100vh;
  position: sticky;
  top: 0;
  border-right: 1px solid var(--outline-variant);
}

.main-content {
  flex-grow: 1;
  padding: var(--spacing-8);
  background-color: var(--surface-container-low);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content-section {
  display: none;
}

.content-section.active {
  display: block;
}

/* --- Sidebar --- */
.logo {
  font-size: 1.75rem;
  font-weight: 500;
  margin-bottom: var(--spacing-8);
  color: var(--primary);
  padding-left: var(--spacing-2);
  letter-spacing: 0.15px;
}

.menu ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-1);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
  padding: var(--spacing-3) var(--spacing-4);
  border-radius: var(--border-radius-xl);
  text-decoration: none;
  color: var(--on-surface);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.1px;
}

.menu-item:hover {
  background-color: var(--secondary-container);
  color: var(--on-secondary-container);
}

.menu-item.active {
  background-color: var(--primary-container);
  color: var(--on-primary-container);
  font-weight: 600;
}

.menu-item .menu-icon {
  flex-shrink: 0;
  stroke-width: 2;
  color: var(--on-surface-variant);
  transition: color 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
}

.menu-item:hover .menu-icon {
  color: var(--on-secondary-container);
}

.menu-item.active .menu-icon {
  color: var(--on-primary-container);
}

.header {
  text-align: center;
  margin-bottom: var(--spacing-8);
  padding-bottom: var(--spacing-4);
  border-bottom: 1px solid var(--outline-variant);
}

h1 {
  color: var(--on-surface);
  font-weight: 400;
  margin: 0 0 var(--spacing-2);
  font-size: 2.25rem;
  letter-spacing: 0px;
}

.card {
  background-color: var(--surface-container);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-1);
  border: 1px solid var(--outline-variant);
  padding: var(--spacing-6);
  margin-bottom: var(--spacing-6);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-6);
}

.card-title {
  font-size: 1.5rem;
  font-weight: 500;
  margin: 0;
  color: var(--on-surface);
  letter-spacing: 0px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-2) var(--spacing-6);
  border-radius: var(--border-radius-xl);
  border: none;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  font-size: 0.875rem;
  letter-spacing: 0.1px;
  min-height: 40px;
  font-family: var(--font-family);
}

.btn-primary {
  background-color: var(--primary-container);
  color: var(--on-primary-container);
}

.btn-outline {
  background-color: transparent;
  border: 1px solid var(--outline);
  color: var(--primary);
}

.btn:hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.btn-primary:hover {
  background-color: var(--primary-container);
  box-shadow: var(--shadow-3);
}

.btn-outline:hover {
  background-color: var(--primary-container);
  color: var(--on-primary-container);
  border-color: var(--primary);
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-1);
}

.btn-group {
  display: flex;
  gap: var(--spacing-2);
}

/* --- Mode Editor --- */
.modes-container {
  display: grid;
  gap: var(--spacing-4);
}

.mode-card {
  background: var(--surface-container-high);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--spacing-4) var(--spacing-6);
  border: 1px solid var(--outline-variant);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
}

.mode-card:hover {
  box-shadow: var(--shadow-2);
  border-color: var(--outline);
}

.mode-card.collapsed {
  cursor: grab;
}

.mode-card.collapsed:active {
  cursor: grabbing;
}

.mode-card.dragging {
  opacity: 0.6;
  border: 2px dashed var(--primary);
  box-shadow: var(--shadow-4);
}

.mode-card.drag-over {
  border-top: 3px solid var(--primary);
  background: var(--primary-container);
}

.mode-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  /* margin-bottom is removed to be handled by card padding */
  margin-bottom: 0;
}

.mode-card-header h2 {
  font-size: 1.25rem;
  margin: 0;
  outline: none;
  flex-grow: 1;
  white-space: normal;
  word-break: break-all;
}

.mode-card-header h2[contenteditable="true"] {
  cursor: text;
  padding: 0.25rem;
}

.mode-card-header h2[contenteditable="true"]:focus {
  background-color: var(--surface-container-low);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.effects-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.effect-item {
  background-color: var(--surface-container-low);
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--outline-variant);
}

.effect-item span {
  flex-grow: 1;
  word-break: break-all; /* Allow long strings to wrap */
}

.effect-item[draggable="true"] {
  cursor: grab;
}

.effect-item[draggable="true"]:active {
  cursor: grabbing;
}

.effect-item.dragging {
    opacity: 0.5;
}

.effect-item.drag-over {
    border-top: 2px solid var(--secondary);
}

.btn-remove-effect {
  background: none;
  border: none;
  color: var(--secondary);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0.25rem;
}

.btn-remove-effect:hover {
  color: var(--danger);
}

.add-effect-container {
  margin-top: 1rem;
}

.add-effect-container select {
  width: 100%;
  padding: var(--spacing-2) var(--spacing-3);
  border-radius: var(--border-radius);
  border: 1px solid var(--outline);
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  font-family: var(--font-family);
  font-size: 0.875rem;
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--spacing-2) center;
  background-size: 16px;
  padding-right: calc(var(--spacing-3) + 20px);
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

.add-effect-container select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-container);
  background-color: var(--surface-container);
}

.add-effect-container select:hover {
  border-color: var(--on-surface-variant);
}

/* 移除，让color-scheme处理 */

.table-container {
  overflow-x: auto;
}

.whitelist-table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--surface-container);
  border-radius: var(--border-radius);
  overflow: hidden;
}

.whitelist-table th {
  background-color: var(--surface-container-high);
  padding: var(--spacing-4);
  text-align: left;
  font-weight: 500;
  color: var(--on-surface);
  font-size: 14px;
  letter-spacing: 0.1px;
}

.whitelist-table td {
  padding: var(--spacing-4);
  border-top: 1px solid var(--outline-variant);
}

.whitelist-table tr:hover {
  background-color: var(--surface-container-low);
}

.pattern-input, select {
  width: 100%;
  padding: var(--spacing-2) var(--spacing-3);
  border: 1px solid var(--outline);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  font-family: var(--font-family);
}

select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--spacing-3) center;
  background-size: 16px;
  padding-right: calc(var(--spacing-3) + 20px);
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

.pattern-input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-container);
  background-color: var(--surface-container);
}

.pattern-input:hover, select:hover {
  border-color: var(--on-surface-variant);
}

/* 让浏览器自动处理下拉选项的颜色方案 */
select {
  color-scheme: light dark;
}

/* 在暗色模式下强制使用暗色方案并改善对比度 */
@media (prefers-color-scheme: dark) {
  select {
    color-scheme: dark;
  }
  
  select option {
    background-color: #2d2d2d !important;
    color: #ffffff !important;
  }
}

/* 强制暗色主题时 */
:root.dark select {
  color-scheme: dark;
}

:root.dark select option {
  background-color: #2d2d2d !important;
  color: #ffffff !important;
}

/* 强制浅色主题时 */
:root.light select {
  color-scheme: light;
}

:root.light select option {
  background-color: #ffffff !important;
  color: #000000 !important;
}

.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 32px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-variant);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  border-radius: 16px;
  border: 2px solid var(--outline);
}

.slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 2px;
  bottom: 2px;
  background-color: var(--outline);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  border-radius: 50%;
  box-shadow: var(--shadow-1);
}

input:checked + .slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

input:checked + .slider:before {
  background-color: var(--surface);
  transform: translateX(20px);
}

.slider:hover {
  box-shadow: 0 0 0 8px rgba(var(--primary), 0.08);
}

input:focus + .slider {
  box-shadow: 0 0 0 8px rgba(var(--primary), 0.12);
}

/* --- Setting Items --- */
.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--spacing-4);
  padding: var(--spacing-4) 0;
}

.setting-item:not(:last-child) {
  border-bottom: 1px solid var(--outline-variant);
}

.setting-label {
  flex: 1;
}

.setting-label label {
  font-weight: 500;
  font-size: 16px;
  color: var(--on-surface);
  margin-bottom: var(--spacing-1);
  display: block;
}

.setting-description {
  font-size: 14px;
  color: var(--on-surface-variant);
  margin: 0;
  line-height: 1.4;
}

.setting-control {
  flex-shrink: 0;
}

.theme-select {
  min-width: 160px;
  padding: var(--spacing-2) var(--spacing-3);
  border: 1px solid var(--outline);
  border-radius: var(--border-radius);
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  font-family: var(--font-family);
  font-size: 14px;
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--spacing-2) center;
  background-size: 16px;
  padding-right: calc(var(--spacing-3) + 20px);
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

.theme-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-container);
  background-color: var(--surface-container);
}

.theme-select:hover {
  border-color: var(--on-surface-variant);
}

/* 移除，让color-scheme处理 */

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--spacing-2);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--on-surface-variant);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
}

.action-btn:hover {
  background-color: var(--secondary-container);
  color: var(--on-secondary-container);
}

.action-btn:active {
  background-color: var(--secondary);
  color: var(--on-secondary);
}

.import-export {
  margin-top: 2rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--on-surface);
}

textarea {
  width: 100%;
  min-height: 120px;
  padding: var(--spacing-3);
  border: 1px solid var(--outline);
  border-radius: var(--border-radius);
  font-family: var(--font-family);
  font-size: 0.875rem;
  resize: vertical;
  margin-bottom: var(--spacing-4);
  background-color: var(--surface-container-low);
  color: var(--on-surface);
  transition: all 0.3s cubic-bezier(0.2, 0.0, 0, 1.0);
  line-height: 1.5;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-container);
  background-color: var(--surface-container);
}

textarea:hover {
  border-color: var(--on-surface-variant);
}

.content-section.active {
  flex-grow: 1;
}

.footer {
  text-align: center;
  margin-top: auto;
  padding: var(--spacing-8) 0 var(--spacing-4);
  color: var(--on-surface-variant);
  font-size: 0.875rem;
  border-top: 1px solid var(--outline-variant);
}

.sidebar-toggle {
  display: none;
  position: absolute; /* Changed from fixed */
  top: 1.25rem;      /* Align with logo/menu items */
  left: 1.5rem;
  z-index: 1001;
  background-color: transparent; /* Remove background */
  border: none;                  /* Remove border */
  border-radius: var(--border-radius);
  width: 44px; /* Increase size for easier clicking */
  height: 44px;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: var(--secondary);
  transition: background-color 0.2s, color 0.2s;
}

.sidebar-toggle:hover {
  background-color: var(--surface-container-low);
  color: var(--primary);
}

.main-content-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 999;
}

@media (max-width: 900px) {
  .container {
    flex-direction: row; /* Keep as row */
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
    transform: translateX(-100%); /* Slide out to the left */
    box-shadow: var(--shadow-2);
    border-right: 1px solid var(--outline-variant);
    padding-top: 60px; /* Add padding to prevent overlap with toggle button */
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    width: 100%;
    padding: 1.5rem; /* Adjust padding for mobile */
  }
  
  .sidebar-toggle {
    display: flex;
  }

  .main-content-overlay.active {
    display: block;
  }
}

@media (max-width: 768px) {
  body {
    padding: 1rem;
  }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .btn-group {
    width: 100%;
  }
  
  .btn {
    flex: 1;
  }
}

/* --- New Styles for Collapsible Cards --- */

.btn-toggle-collapse {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  margin-left: -0.5rem; /* Align with card padding */
  color: var(--secondary);
  transition: transform 0.3s ease, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-toggle-collapse:hover {
  color: var(--primary);
}

.btn-toggle-collapse .menu-icon {
  transition: transform 0.3s ease;
}

.collapsed .btn-toggle-collapse .menu-icon {
  transform: rotate(0deg);
}

.mode-card:not(.collapsed) .btn-toggle-collapse .menu-icon {
  transform: rotate(90deg);
}

.mode-summary {
  display: none;
  padding: 0.75rem 0 0.25rem;
  color: var(--on-surface-variant);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

.mode-card.collapsed .mode-summary {
  display: block;
}

.mode-card-content {
  display: block;
  padding-top: 1rem;
  border-top: 1px solid var(--outline-variant);
  margin-top: 1rem;
}

.mode-card.collapsed .mode-card-content {
  display: none;
}

.effect-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-move-effect {
  background: none;
  border: none;
  color: var(--secondary);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.25rem;
  border-radius: var(--border-radius);
}

.btn-move-effect:hover:not(:disabled) {
  background-color: var(--surface-container-low);
  color: var(--primary);
}

.btn-move-effect:disabled {
  color: var(--outline-variant);
  cursor: not-allowed;
}

/* --- About Section --- */
.about-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.about-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.extension-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--border-radius);
}

.extension-name {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0;
}

.version-info {
  font-size: 1rem;
  color: var(--on-surface-variant);
  margin: 0.25rem 0 0;
}

.about-content p {
  margin-top: 0;
  line-height: 1.6;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.info-item {
  background-color: var(--surface-container-low);
  padding: 1rem;
  border-radius: var(--border-radius);
  border: 1px solid var(--outline-variant);
}

.info-item strong {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--on-surface);
}

.info-item a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.info-item a:hover {
  text-decoration: underline;
}