/* ============================================================
   UltraProx — Browser Chrome UI
   Dark-first, CSS custom properties for theming
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Tokens ── */
:root {
  --bg-chrome:       #202124;
  --bg-toolbar:      #292a2d;
  --bg-tab-bar:      #1e1f22;
  --bg-tab-inactive: #2a2b2e;
  --bg-tab-active:   #292a2d;
  --bg-tab-hover:    #35363a;
  --bg-address:      #303134;
  --bg-address-focus:#404144;
  --bg-dropdown:     #303134;
  --bg-context:      #303134;
  --bg-bookmarks:    #25262a;
  --bg-statusbar:    #1a1b1e;
  --bg-modal:        #292a2d;
  --bg-modal-overlay:rgba(0,0,0,.6);
  --bg-toast:        #3c3d41;
  --bg-progress:     #8ab4f8;

  --text-primary:    #e8eaed;
  --text-secondary:  #9aa0a6;
  --text-tab-inactive:#9aa0a6;
  --text-tab-active: #e8eaed;
  --text-address:    #e8eaed;
  --text-placeholder:#6b6f76;
  --text-link:       #8ab4f8;
  --text-error:      #f28b82;

  --border:          #3c3d41;
  --border-tab:      #3c3d41;
  --border-address:  transparent;
  --border-focus:    #8ab4f8;

  --btn-hover:       rgba(255,255,255,.08);
  --btn-active:      rgba(255,255,255,.14);

  --tab-close-hover: rgba(255,255,255,.15);
  --tab-indicator:   #8ab4f8;

  --scrollbar-track: #202124;
  --scrollbar-thumb: #5f6368;

  --shadow-dropdown:  0 4px 16px rgba(0,0,0,.5);
  --shadow-modal:     0 8px 32px rgba(0,0,0,.7);

  --radius-tab:      8px;
  --radius-btn:      4px;
  --radius-address:  20px;
  --radius-modal:    10px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-ui:    13px;
  --font-size-tab:   12px;
  --font-size-addr:  14px;

  --transition-fast: 0.12s ease;
  --transition-med:  0.22s ease;

  --toolbar-h: 48px;
  --tabbar-h:  36px;
  --bookmarks-h: 30px;
  --statusbar-h: 22px;
}

[data-theme="light"] {
  --bg-chrome:       #dee1e6;
  --bg-toolbar:      #f1f3f4;
  --bg-tab-bar:      #dee1e6;
  --bg-tab-inactive: #d2d5da;
  --bg-tab-active:   #f1f3f4;
  --bg-tab-hover:    #c5c8cd;
  --bg-address:      #fff;
  --bg-address-focus:#fff;
  --bg-dropdown:     #fff;
  --bg-context:      #fff;
  --bg-bookmarks:    #f1f3f4;
  --bg-statusbar:    #e8eaed;
  --bg-modal:        #fff;
  --bg-modal-overlay:rgba(0,0,0,.4);
  --bg-toast:        #323232;
  --bg-progress:     #1a73e8;

  --text-primary:    #202124;
  --text-secondary:  #5f6368;
  --text-tab-inactive:#5f6368;
  --text-tab-active: #202124;
  --text-address:    #202124;
  --text-placeholder:#80868b;
  --text-link:       #1a73e8;
  --text-error:      #c5221f;

  --border:          #c6c7cb;
  --border-tab:      #c6c7cb;
  --border-address:  #dadce0;
  --border-focus:    #1a73e8;

  --btn-hover:       rgba(0,0,0,.06);
  --btn-active:      rgba(0,0,0,.10);

  --tab-close-hover: rgba(0,0,0,.10);
  --tab-indicator:   #1a73e8;

  --scrollbar-track: #f1f3f4;
  --scrollbar-thumb: #bdc1c6;

  --shadow-dropdown: 0 4px 16px rgba(0,0,0,.2);
  --shadow-modal:    0 8px 32px rgba(0,0,0,.25);
}

/* ── Base ── */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: var(--font-size-ui);
  background: var(--bg-chrome);
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #80868b; }

/* ── Layout ── */
#browser {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Progress bar ── */
#progress-bar {
  position: absolute;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--bg-progress);
  z-index: 1000;
  transition: width 0.3s ease, opacity 0.4s ease;
  border-radius: 0 2px 2px 0;
  pointer-events: none;
  opacity: 0;
}
#progress-bar.loading {
  opacity: 1;
}

/* ── Tab Bar ── */
#tab-bar {
  display: flex;
  align-items: flex-end;
  height: var(--tabbar-h);
  background: var(--bg-tab-bar);
  padding: 0 4px 0 4px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

#tabs-container {
  display: flex;
  align-items: flex-end;
  flex: 1;
  overflow: hidden;
  height: 100%;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  min-width: 80px;
  max-width: 200px;
  flex: 1;
  padding: 0 8px 0 10px;
  background: var(--bg-tab-inactive);
  color: var(--text-tab-inactive);
  font-size: var(--font-size-tab);
  cursor: pointer;
  border-radius: var(--radius-tab) var(--radius-tab) 0 0;
  border: 1px solid var(--border-tab);
  border-bottom: none;
  margin-right: 2px;
  position: relative;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 1;
  overflow: hidden;
}
.tab:hover { background: var(--bg-tab-hover); }
.tab.active {
  background: var(--bg-tab-active);
  color: var(--text-tab-active);
  z-index: 2;
}
.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 2px;
  background: var(--tab-indicator);
  border-radius: 2px 2px 0 0;
}

.tab-favicon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 2px;
}
.tab-favicon.loading {
  animation: spin 0.8s linear infinite;
  filter: invert(60%);
}

.tab-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.tab-close {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  font-size: 11px;
  line-height: 1;
  transition: opacity var(--transition-fast), background var(--transition-fast);
}
.tab:hover .tab-close,
.tab.active .tab-close { opacity: 1; }
.tab-close:hover { background: var(--tab-close-hover); }

#new-tab-btn {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: 4px;
  transition: background var(--transition-fast), color var(--transition-fast);
}
#new-tab-btn:hover { background: var(--btn-hover); color: var(--text-primary); }

/* ── Toolbar ── */
#toolbar {
  display: flex;
  align-items: center;
  height: var(--toolbar-h);
  background: var(--bg-toolbar);
  padding: 0 8px;
  gap: 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.toolbar-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}
.toolbar-btn:hover { background: var(--btn-hover); color: var(--text-primary); }
.toolbar-btn:active { background: var(--btn-active); }
.toolbar-btn:disabled,
.toolbar-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}
.toolbar-btn svg { width: 18px; height: 18px; }

/* ── Address Bar ── */
#address-bar-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

#address-bar {
  width: 100%;
  height: 32px;
  background: var(--bg-address);
  border: 1px solid var(--border-address);
  border-radius: var(--radius-address);
  padding: 0 36px 0 36px;
  font-size: var(--font-size-addr);
  color: var(--text-address);
  outline: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  font-family: var(--font);
}
#address-bar::placeholder { color: var(--text-placeholder); }
#address-bar:focus {
  background: var(--bg-address-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--border-focus) 30%, transparent);
}

#lock-icon {
  position: absolute;
  left: 10px;
  display: flex; align-items: center;
  pointer-events: none;
  z-index: 1;
}
#lock-icon svg { width: 14px; height: 14px; }
#lock-icon.secure { color: #34a853; }
#lock-icon.insecure { color: var(--text-error); }
#lock-icon.neutral { color: var(--text-secondary); }

#address-clear {
  position: absolute;
  right: 10px;
  display: none;
  align-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  z-index: 1;
}
#address-clear:hover { color: var(--text-primary); }
#address-bar:not(:placeholder-shown) + #address-clear,
#address-bar:focus + #address-clear { display: flex; }

/* ── History Dropdown ── */
#history-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-dropdown);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-dropdown);
  z-index: 200;
  max-height: 300px;
  overflow-y: auto;
  padding: 4px 0;
}
#history-dropdown.open { display: block; }

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.history-item:hover { background: var(--btn-hover); }
.history-item-favicon { width: 14px; height: 14px; border-radius: 2px; flex-shrink: 0; }
.history-item-url { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-secondary); }
.history-item-title { font-size: 12px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.history-clear { display: block; padding: 6px 12px; font-size: 11px; color: var(--text-link); cursor: pointer; text-align: right; border-top: 1px solid var(--border); }
.history-clear:hover { text-decoration: underline; }
.history-section-header { padding: 6px 12px 2px; font-size: 11px; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

/* ── Bookmarks Bar ── */
#bookmarks-bar {
  display: flex;
  align-items: center;
  height: var(--bookmarks-h);
  background: var(--bg-bookmarks);
  padding: 0 8px;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
#bookmarks-bar::-webkit-scrollbar { display: none; }
#bookmarks-bar.hidden { display: none; }

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}
.bookmark-item:hover { background: var(--btn-hover); }
.bookmark-item img { width: 12px; height: 12px; }

/* ── Content Area ── */
#content-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-chrome);
}

.tab-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  background: #fff;
}
.tab-frame.active { display: block; }

/* New Tab Page */
.new-tab-page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--bg-chrome);
}
.new-tab-page.active { display: flex; }

.new-tab-logo {
  font-size: 48px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -2px;
}
.new-tab-search {
  display: flex;
  width: min(600px, 90vw);
  position: relative;
}
.new-tab-search input {
  width: 100%;
  height: 44px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--bg-address);
  color: var(--text-primary);
  font-size: 16px;
  padding: 0 48px 0 20px;
  outline: none;
  font-family: var(--font);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.new-tab-search input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--border-focus) 25%, transparent);
}
.new-tab-search-btn {
  position: absolute;
  right: 4px; top: 4px;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--border-focus);
  color: #fff;
  cursor: pointer;
}
.new-tab-shortcuts {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
.shortcut-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background var(--transition-fast);
}
.shortcut-item:hover { background: var(--btn-hover); }
.shortcut-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  background: var(--bg-address);
}
.shortcut-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Status Bar ── */
#status-bar {
  display: flex;
  align-items: center;
  height: var(--statusbar-h);
  background: var(--bg-statusbar);
  padding: 0 10px;
  font-size: 11px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
  overflow: hidden;
}
#status-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#status-security { display: flex; align-items: center; gap: 3px; }

/* ── Context Menu ── */
#context-menu {
  position: fixed;
  background: var(--bg-context);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-dropdown);
  z-index: 500;
  min-width: 180px;
  padding: 4px 0;
  display: none;
}
#context-menu.open { display: block; }

.ctx-item {
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition-fast);
}
.ctx-item:hover { background: var(--btn-hover); }
.ctx-separator { height: 1px; background: var(--border); margin: 4px 0; }
.ctx-item svg { width: 14px; height: 14px; opacity: 0.7; }

/* ── Settings Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  z-index: 800;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}
#modal-overlay.open { display: flex; }

#settings-modal {
  background: var(--bg-modal);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-modal);
  width: min(480px, 94vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.18s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}
.modal-close {
  cursor: pointer;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition-fast);
}
.modal-close:hover { background: var(--btn-hover); }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.setting-label { font-size: 13px; color: var(--text-primary); }
.setting-sublabel { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.setting-group { display: flex; flex-direction: column; }

/* Toggle Switch */
.toggle {
  position: relative;
  width: 38px; height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.toggle input:checked ~ .toggle-track { background: var(--tab-indicator); }
.toggle-thumb {
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition-fast);
  pointer-events: none;
}
.toggle input:checked ~ .toggle-track .toggle-thumb { transform: translateX(18px); }

/* Select */
.setting-select {
  background: var(--bg-address);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  padding: 4px 8px;
  outline: none;
  cursor: pointer;
}

/* Danger btn */
.btn-danger {
  background: transparent;
  border: 1px solid var(--text-error);
  color: var(--text-error);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.btn-danger:hover { background: color-mix(in srgb, var(--text-error) 12%, transparent); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--bg-toast);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
  animation: toastIn 0.2s ease forwards;
  pointer-events: none;
}
.toast.out { animation: toastOut 0.25s ease forwards; }

/* ── Loading indicator in tab ── */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }
@keyframes slideUp { from { transform: translateY(12px); opacity:0 } to { transform: translateY(0); opacity:1 } }
@keyframes toastIn { from { opacity:0; transform:translateY(8px) } to { opacity:1; transform:translateY(0) } }
@keyframes toastOut { from { opacity:1 } to { opacity:0; transform:translateY(-8px) } }

/* ── Mobile / responsive ── */
@media (max-width: 600px) {
  :root {
    --toolbar-h: 44px;
    --tabbar-h: 32px;
  }
  .tab { min-width: 60px; padding: 0 6px; }
  .tab-title { display: none; }
  #toolbar { gap: 2px; padding: 0 4px; }
  .toolbar-btn { width: 28px; height: 28px; }
  #address-bar { font-size: 13px; }
  #btn-home, #btn-settings { display: none; }
}
