/* ==== Theme variables ==== */
:root {
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --text: #1f2937;
  --border: #e5e7eb;
  --input-bg: #ffffff;
  --tab-bg: #e0e7ff;
  --tab-active-bg: #ffffff;
  --tab-active-text: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}
[data-theme="dark"] {
  --bg: #111827;
  --card-bg: #1f2937;
  --text: #f3f4f6;
  --border: #374151;
  --input-bg: #374151;
  --tab-bg: #374151;
  --tab-active-bg: #4b5563;
  --tab-active-text: #60a5fa;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
}

/* ==== Global ==== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: background .2s, color .2s;
  width: 100%;
}

/* Chrome Extension specific styles */
body.extension-popup {
  min-width: 600px;
  max-width: 600px;
  width: 600px;
  min-height: 500px;
  max-height: 500px;
  height: 500px;
  overflow: hidden;
}

body.extension-popup main.container {
  height: calc(500px - 160px);
  overflow-y: auto;
  overflow-x: hidden;
}

body.extension-popup .card {
  margin-bottom: 0;
}

/* Chrome Extension popup constraints */
@media (max-width: 800px) {
  body {
    min-height: 600px;
    max-height: 600px;
    overflow-y: auto;
  }
}

/* ==== Layout ==== */
header, footer { background: var(--card-bg); }
header { box-shadow: var(--shadow); }
.container { 
  max-width: 1200px;
  margin: auto; 
  padding: 1rem;
  width: 100%;
}

/* Extension: Compact container */
body.extension-popup .container {
  max-width: 100%;
  padding: 0.75rem;
}

main { 
  flex: 1; 
  padding: 1rem 0;
}

/* Extension: Adjust main padding */
body.extension-popup main {
  padding: 0.5rem 0;
}

footer { text-align: center; padding: 1rem 0; font-size: .875rem; color: var(--text); opacity: .8; }

/* Extension: Compact footer */
body.extension-popup footer {
  padding: 0.5rem 0;
  font-size: 0.75rem;
}

@media (min-width: 768px) {
  .container { padding: 1.5rem; }
  main { padding: 2rem 0; }
}

/* Override media query for extension */
body.extension-popup .container {
  padding: 0.75rem !important;
}

body.extension-popup main {
  padding: 0.5rem 0 !important;
}

/* ==== Title Bar ==== */
.title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  position: relative;
  flex-wrap: wrap;
  gap: .5rem;
}

/* Extension: Compact title bar */
body.extension-popup .title-bar {
  margin-bottom: 0.5rem;
  gap: 0.25rem;
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* Extension: Smaller title */
body.extension-popup .app-title {
  font-size: 1.1rem;
}

@media (min-width: 640px) {
  .app-title {
    font-size: 1.75rem;
  }
  
  /* Keep extension title compact even on larger screens */
  body.extension-popup .app-title {
    font-size: 1.1rem;
  }
}

/* ==== Header Buttons ==== */
.header-buttons {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ==== Tour Button ==== */
.btn-tour {
  background: #16a34a;
  color: white;
  border: none;
  font-size: 0.875rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  transition: all 0.2s;
  font-weight: 500;
  white-space: nowrap;
}

@media (min-width: 640px) {
  .btn-tour {
    font-size: 1rem;
    padding: 0.5rem 1rem;
  }
}

.btn-tour:hover {
  background: #15803d;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(22, 163, 74, 0.3);
}

/* ==== Theme toggle ==== */
.theme-toggle {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: .5rem;
  border-radius: .5rem;
  transition: background .2s;
}

@media (min-width: 640px) {
  .theme-toggle {
    font-size: 1.5rem;
  }
}

.theme-toggle:hover { background: rgba(0,0,0,.05); }
[data-theme="dark"] .theme-toggle:hover { background: rgba(255,255,255,.1); }

/* ==== Tabs ==== */
.tabs {
  display: flex;
  gap: .5rem;
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  height: 4px;
}

.tabs::-webkit-scrollbar-track {
  background: transparent;
}

.tabs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.tab {
  padding: .5rem .75rem;
  background: var(--tab-bg);
  border-radius: .5rem;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  font-size: .875rem;
}

@media (min-width: 640px) {
  .tab {
    padding: .5rem 1rem;
    font-size: 1rem;
  }
}

.tab.active {
  background: var(--tab-active-bg);
  color: var(--tab-active-text);
  box-shadow: var(--shadow);
}

/* ==== Card ==== */
.card {
  background: var(--card-bg);
  border-radius: .75rem;
  padding: 1rem;
  box-shadow: var(--shadow);
  transition: background .2s;
}

/* Extension: Compact card */
body.extension-popup .card {
  padding: 0.75rem;
  border-radius: 0.5rem;
}

@media (min-width: 768px) {
  .card {
    padding: 1.5rem;
  }
  
  /* Keep extension card compact */
  body.extension-popup .card {
    padding: 0.75rem;
  }
}

/* ==== Form controls ==== */
label { display: block; margin-bottom: .25rem; font-size: .875rem; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--tab-active-text);
  box-shadow: 0 0 0 2px rgba(37,99,235,.2);
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  box-shadow: 0 0 0 2px rgba(96,165,250,.3);
}
.grid { 
  display: grid; 
  gap: .75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid { 
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

/* ==== Buttons ==== */
.btn {
  display: inline-block;
  padding: .625rem 1rem;
  border: none;
  border-radius: .5rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
  font-size: .875rem;
}

@media (min-width: 640px) {
  .btn {
    padding: .75rem 1.5rem;
    font-size: 1rem;
  }
}

.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #64748b; color: white; }
.btn-secondary:hover { background: #475569; }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc2626; color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-export { background: #7c3aed; color: white; }
.btn-export:hover { background: #6d28d9; }

/* ==== Overlay ==== */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
  padding: 1rem;
}

/* Extension: Full overlay */
body.extension-popup .overlay {
  padding: 0.5rem;
}

.overlay-content {
  background: var(--card-bg);
  border-radius: .75rem;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,.1), 0 10px 10px -5px rgba(0,0,0,.04);
  max-width: 95vw;
  max-height: 90vh;
  width: 700px;
  display: flex;
  flex-direction: column;
}

/* Extension: Compact overlay */
body.extension-popup .overlay-content {
  max-width: 95%;
  max-height: 95%;
  width: 550px;
}

@media (min-width: 768px) {
  .overlay-content {
    max-width: 90vw;
    max-height: 85vh;
  }
  
  /* Keep extension overlay compact */
  body.extension-popup .overlay-content {
    max-width: 95%;
    max-height: 95%;
    width: 550px;
  }
}

/* ==== Overlay Content Small ==== */
.overlay-content-small {
  max-width: 500px;
  width: 90%;
}

body.extension-popup .overlay-content-small {
  max-width: 450px;
  width: 85%;
}

/* ==== Overlay Header ==== */
.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.overlay-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text);
}

.overlay-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--text);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: .375rem;
  transition: background .2s;
}

.overlay-close:hover {
  background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .overlay-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ==== Overlay Body ==== */
.overlay-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.key-item {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: all .2s;
}

.key-item:hover {
  border-color: var(--tab-active-text);
  box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}

[data-theme="dark"] .key-item:hover {
  box-shadow: 0 0 0 2px rgba(96,165,250,.2);
}

.key-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}

.key-item-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.key-item-type {
  background: var(--tab-active-text);
  color: white;
  padding: .25rem .5rem;
  border-radius: .25rem;
  font-size: .75rem;
  font-weight: 500;
}

.key-item-date {
  font-size: .875rem;
  color: var(--text);
  opacity: .7;
  margin-bottom: .5rem;
}

.key-item-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: .375rem;
  padding: .5rem;
  font-family: 'Courier New', monospace;
  font-size: .75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  opacity: .8;
}

.key-item.expanded .key-item-preview {
  white-space: pre-wrap;
  word-break: break-all;
}

.key-item-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}

.btn-small {
  padding: .375rem .75rem;
  font-size: .875rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text);
  opacity: .6;
}

/* ==== Collection Cards ==== */
.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: .5rem;
  cursor: pointer;
  transition: all .2s;
  user-select: none;
}

@media (min-width: 640px) {
  .collapsible-header {
    padding: 1rem;
  }
}

.collapsible-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.collapsible-icon {
  font-size: .875rem;
  color: var(--text);
  transition: transform .2s;
}

.collapsible-header.expanded .collapsible-icon {
  transform: rotate(-180deg);
}

.collections-scroll-container {
  max-height: 300px;
  overflow-y: auto;
  padding-right: .5rem;
}

/* Extension: Adjust scroll container height */
body.extension-popup .collections-scroll-container {
  max-height: 200px;
}

@media (min-width: 768px) {
  .collections-scroll-container {
    max-height: 400px;
  }
  
  /* Keep extension height fixed */
  body.extension-popup .collections-scroll-container {
    max-height: 200px;
  }
}

@media (min-width: 1024px) {
  .collections-scroll-container {
    max-height: 500px;
  }
  
  /* Keep extension height fixed */
  body.extension-popup .collections-scroll-container {
    max-height: 200px;
  }
}

.collections-scroll-container::-webkit-scrollbar {
  width: 8px;
}

.collections-scroll-container::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 4px;
}

.collections-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.collections-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--tab-active-text);
}

.collection-card {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  transition: all .2s;
}

.collection-card:hover {
  border-color: var(--tab-active-text);
  box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}

[data-theme="dark"] .collection-card:hover {
  box-shadow: 0 0 0 2px rgba(96,165,250,.2);
}

.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}

.collection-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.collection-badge {
  background: var(--tab-active-text);
  color: white;
  padding: .25rem .5rem;
  border-radius: .25rem;
  font-size: .75rem;
  font-weight: 500;
}

.collection-desc {
  font-size: .875rem;
  color: var(--text);
  opacity: .7;
  margin-bottom: .75rem;
}

.collection-meta {
  font-size: .75rem;
  color: var(--text);
  opacity: .6;
  margin-bottom: .75rem;
}

.collection-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .collection-actions {
    flex-direction: column;
  }
  
  .collection-actions .btn-small {
    width: 100%;
  }
}

/* ==== Misc ==== */
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.flex { 
  display: flex; 
  gap: .5rem;
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .flex {
    flex-direction: column;
  }
  
  .flex .btn {
    width: 100%;
  }
}

.flex-1 { flex: 1; min-width: 0; }
.w-full { width: 100%; }
pre {
  background: var(--input-bg);
  padding: .75rem;
  border-radius: .5rem;
  overflow: auto;
  font-size: .75rem;
  border: 1px solid var(--border);
}

@media (min-width: 640px) {
  pre {
    font-size: .8rem;
  }
}

/* ==== Key Type Indicator ==== */
#keyTypeIndicator {
  transition: opacity 0.2s;
}

#keyTypeDisplay {
  font-weight: 600;
  color: var(--tab-active-text);
  font-family: 'Courier New', monospace;
}

/* ==== Section Header ==== */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

body.extension-popup .section-header {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
}

.section-header h2 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

body.extension-popup .section-header h2 {
  font-size: 1.1rem;
}

/* ==== Help Button ==== */
.btn-help {
  background: var(--tab-active-text);
  color: white;
  border: none;
  padding: 0.375rem;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
}

body.extension-popup .btn-help {
  padding: 0.25rem;
  font-size: 0.875rem;
  width: 1.75rem;
  height: 1.75rem;
}

.btn-help:hover {
  background: var(--tab-active-bg);
  color: var(--tab-active-text);
  border: 1px solid var(--tab-active-text);
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 2px 4px rgba(37,99,235,0.2);
}

[data-theme="dark"] .btn-help:hover {
  box-shadow: 0 2px 4px rgba(96,165,250,0.3);
}

/* ==== Help Content Styling ==== */
#helpContent h3 {
  color: var(--tab-active-text);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

#helpContent h3:first-child {
  margin-top: 0;
}

#helpContent p {
  line-height: 1.6;
  margin: 0.75rem 0;
}

#helpContent ul {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

#helpContent li {
  margin: 0.5rem 0;
  line-height: 1.5;
}

#helpContent details {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

#helpContent summary {
  font-weight: 600;
  color: var(--tab-active-text);
  cursor: pointer;
  user-select: none;
}

#helpContent details[open] {
  background: var(--bg);
}

#helpContent details p {
  margin: 0.5rem 0 0.25rem 0;
  padding-left: 0.5rem;
}

/* Remove old info-box styles as they're no longer needed */
/* Keep warning and note styles for help overlay */

/* ==== File Picker ==== */
.file-picker {
  min-height: 100px;
}

#inputModeToggle {
  display: flex;
  gap: 0.5rem;
}

#inputModeToggle button {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s;
}

#inputModeToggle button:hover {
  background: var(--tab-active-text);
  color: white;
  border-color: var(--tab-active-text);
}

#inputModeToggle button.active {
  background: var(--tab-active-text);
  color: white;
  border-color: var(--tab-active-text);
  font-weight: 600;
}

body.extension-popup #inputModeToggle button {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

/* ==== AAD Input ==== */
#aadInput {
  font-family: 'Courier New', monospace;
}

/* ==== Tour Content Styling ==== */
#tourContent h3 {
  color: var(--tab-active-text);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
}

#tourContent h3:first-child {
  margin-top: 0;
}

#tourContent h4 {
  color: var(--text);
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

#tourContent p {
  line-height: 1.6;
  margin: 0.75rem 0;
  color: var(--text);
}

#tourContent ul, #tourContent ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  color: var(--text);
}

#tourContent li {
  margin: 0.5rem 0;
  line-height: 1.5;
}

#tourContent strong {
  color: var(--text);
  font-weight: 600;
}

/* Tour info boxes */
#tourContent div[style*="background"] {
  border-radius: 0.5rem;
  padding: 1rem;
}

/* Security warning box (red) */
#tourContent div[style*="#fef2f2"] {
  background: #fef2f2 !important;
  border-left: 4px solid #dc2626;
  color: #991b1b;
}

[data-theme="dark"] #tourContent div[style*="#fef2f2"] {
  background: #7f1d1d !important;
  color: #fecaca;
}

/* Best practice box (blue/primary) */
#tourContent div[style*="var(--input-bg)"] {
  background: var(--input-bg) !important;
  color: var(--text);
}

/* Success/CTA box (green) */
#tourContent div[style*="var(--tab-active-text)"] {
  background: var(--tab-active-text) !important;
  color: white !important;
}

#tourContent div[style*="var(--tab-active-text)"] strong,
#tourContent div[style*="var(--tab-active-text)"] p {
  color: white !important;
}

.tour-navigation button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
