/* CSS Variables for themes */
html[data-theme="dark"] {
  --bg-primary: #272725;
  --bg-secondary: #171717;
  --border-color: #383838;
  --text-color: #ffffff;
  --tab-active-bg: #272725;
  --tab-hover-bg: #333333;
  --icon-color: #8a8a8a;
  --icon-hover-color: #ffffff;
  --error-color: #e53935;
  --offline-indicator-color: #e53935;
  --loading-overlay-bg: rgba(30, 30, 30, 0.8);
  --loading-spinner-color: #ffffff;
}

html[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --border-color: #e0e0e0;
  --text-color: #000000;
  --tab-active-bg: #e8e8e8;
  --tab-hover-bg: #efefef;
  --icon-color: #666666;
  --icon-hover-color: #000000;
  --error-color: #e53935;
  --offline-indicator-color: #e53935;
  --loading-overlay-bg: rgba(240, 240, 240, 0.8);
  --loading-spinner-color: #333333;
}

.container {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  border: none;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
}

.browser-chrome {
  display: flex;
  flex-direction: column;
  width: 100%;
  position: relative;
}

.tab-bar {
  display: flex;
  padding: 6px;
  gap: 4px;
  height: 36px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  align-items: center;

  &::-webkit-scrollbar {
    display: none;
  }
}

.tab {
  display: flex;
  align-items: center;
  padding: 0 12px;
  min-width: 120px;
  max-width: 200px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-color);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  gap: 8px;
  transition: background-color 0.2s;

  &:hover {
    background-color: var(--tab-hover-bg);
  }

  &.active {
    background-color: var(--tab-active-bg);
  }
}

.tab-favicon {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.tab-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-close {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.6;
  font-size: 14px;
  line-height: 1;

  &:hover {
    background: rgba(255, 255, 255, 0.1);
    opacity: 1;
  }
}

.address-bar {
  display: flex;
  align-items: center;
  padding: 0 8px;
  height: 40px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.nav-buttons {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  margin-right: 8px;
}

.nav-button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--icon-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  padding: 0;
  border-radius: 4px;
  transition: all 0.2s;

  &:hover {
    color: var(--icon-hover-color);
    background: rgba(255, 255, 255, 0.1);
  }

  &:disabled {
    cursor: default;

    &:hover {
      background: transparent;
    }
  }
}

.url-bar {
  width: 100%;
  height: 28px;
  padding: 0 12px;
  background: var(--bg-primary);
  border-radius: 4px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-color);
  font-family: system-ui, -apple-system, sans-serif;

  &:focus-within {
    outline: none;
    background: var(--tab-hover-bg);
  }
}

.url-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  outline: none;
  width: 100%;
}

.content {
  min-height: 0;
  flex: 1;
  overflow: hidden;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.canvas-container {
  position: absolute;
  height: 100%;
  width: 100%;
  display: none;

  &.active {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &.loading::before {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-color);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 16px;
    z-index: 5;
  }

  &.error::before {
    content: "Session released";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 16px;
    z-index: 5;
  }

  &.tab-switching::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--loading-overlay-bg);
    z-index: 10;
  }

  &.tab-switching::before {
    content: "";
    position: absolute;
    width: 40px;
    height: 40px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 4px solid transparent;
    border-top-color: var(--loading-spinner-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 11;
  }
}

.canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  margin: auto;
  object-fit: contain;
}

.connection-status {
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 36px;
  color: var(--text-color);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
  box-sizing: border-box;
  min-width: 140px;
  flex-shrink: 0;

  &.offline {
    display: flex;
  }

  &.online {
    display: none;
  }

  &.connecting {
    display: none;
  }
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  display: inline-block;
  flex-shrink: 0;

  &.offline {
    background-color: var(--offline-indicator-color);
  }
}

.url-security-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;

  svg {
    width: 18px;
    height: 18px;
    fill: var(--icon-color);
  }

  &.secure svg {
    fill: #4CAF50;
  }
}

.tab-favicon-spinner {
  width: 16px;
  height: 16px;
  display: none;
  position: relative;

  &::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: 2px;
    left: 2px;
    border: 2px solid var(--icon-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spinner-rotation 0.8s linear infinite;
  }
}

.tab.loading {
  .tab-favicon {
    display: none;
  }

  .tab-favicon-spinner {
    display: block;
  }
}

@keyframes spin {
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes spinner-rotation {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
