/* =====================================================
   CRA-Portal Layout System
   Dark theme layout components
   ===================================================== */

/* ---- App Structure ---- */
.app-body {
  min-height: 100vh;
  background-color: var(--bg-body);
  color: var(--text-primary);
}

.app-root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover));
  color: #ffffff;
}

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

.logo-subtitle {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-pill {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background-color: var(--brand-primary-soft);
  color: var(--brand-primary);
}

.language-select {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 6px;
}

/* ---- Shell Layout ---- */
.app-shell {
  display: flex;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Sidebar ---- */
.app-sidebar {
  width: 240px;
  min-width: 240px;
  border-right: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.sidebar-nav li a:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-nav li a.is-active,
.sidebar-nav li a.is-active:hover {
  background-color: var(--brand-primary);
  color: #ffffff;
}

.sidebar-section-label {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  padding: 0 0.75rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.back-to-site {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.15s ease;
}

.back-to-site:hover {
  color: var(--accent);
  text-decoration: none;
}

/* ---- Main Content ---- */
.app-main {
  flex: 1;
  padding: 2rem;
  min-width: 0;
}

/* ---- Footer ---- */
.app-footer {
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.footer-divider {
  opacity: 0.5;
}

/* ---- Page Header ---- */
.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
}

.page-subtitle {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ---- Sections ---- */
.section {
  margin-top: 2rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.section-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* ---- Grid System ---- */
.grid {
  display: grid;
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gap-sm {
  gap: 0.75rem;
}

.gap-md {
  gap: 1rem;
}

.gap-lg {
  gap: 1.5rem;
}

/* ---- Cards ---- */
.card {
  background-color: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  padding: 1.25rem 1.5rem;
}

/* ---- KPI Cards ---- */
.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kpi-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0;
}

.kpi-value {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
}

.btn-block {
  width: 100%;
}

.btn-small {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-primary {
  background-color: var(--brand-primary);
  color: #ffffff;
  border-color: var(--brand-primary);
}

.btn-primary:hover {
  background-color: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
}

.btn-secondary {
  background-color: var(--brand-primary-soft);
  color: var(--brand-primary);
  border-color: transparent;
}

.btn-secondary:hover {
  background-color: rgba(59, 130, 246, 0.25);
}

.btn-ghost {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background-color: #dc2626;
  border-color: #dc2626;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.25rem;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon:last-child {
  margin-right: 0;
}

.btn-edit:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.btn-delete:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---- Quick Actions ---- */
.quick-actions {
  margin-top: 1rem;
}

/* ---- Tables ---- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: var(--bg-surface-elevated);
}

.table tbody tr:hover {
  background-color: var(--bg-hover);
}

.table td {
  color: var(--text-primary);
}

.table-footer {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
}

.actions-cell {
  white-space: nowrap;
}

/* ---- Forms ---- */
.form-grid {
  display: grid;
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-field input,
.form-field textarea,
.form-field select {
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-body);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input::placeholder,
.form-field textarea::placeholder {
  color: var(--text-muted);
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-soft);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

/* ---- Search Input ---- */
.search-input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.9rem;
  min-width: 250px;
  background-color: var(--bg-body);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-soft);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ---- Status Badges ---- */
.status-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-in_development {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-on_market {
  background: var(--success-soft);
  color: var(--success);
}

.status-eol {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-archived {
  background: var(--bg-surface-elevated);
  color: var(--text-muted);
}

/* ---- Modals ---- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-surface);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1001;
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  color: var(--text-secondary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
}

.modal .form-grid {
  padding: 1.5rem;
}

/* ---- Auth Layout (login/register/forgot) ---- */
.auth-body {
  background-color: var(--bg-body) !important;
  color: var(--text-primary) !important;
  min-height: 100vh;
}

.auth-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
}

.auth-brand:hover {
  text-decoration: none;
}

.auth-brand .brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover));
  color: #fff;
  padding: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s ease;
}

.back-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 1.5rem 1.5rem;
}

.auth-card {
  max-width: 440px;
  width: 100%;
  background-color: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2rem;
}

.auth-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: var(--text-primary) !important;
}

.auth-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary) !important;
  margin: 0;
  line-height: 1.5;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary) !important;
}

.form-label span {
  color: var(--text-secondary) !important;
  font-weight: 500;
}

.form-input {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-body) !important;
  color: var(--text-primary) !important;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-primary-soft);
}

.form-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.space-between {
  justify-content: space-between;
}

.form-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary) !important;
}

.form-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand-primary);
}

.text-link {
  font-size: 0.85rem;
  color: var(--accent) !important;
  transition: color 0.15s ease;
}

.text-link:hover {
  color: var(--accent-hover) !important;
  text-decoration: underline;
}

.auth-footer {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-end;
}

.auth-footer-secondary {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary) !important;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.auth-footer-secondary .text-link {
  font-weight: 500;
}

.language-switch {
  display: flex;
  gap: 0.5rem;
}

.lang-btn {
  border: 1px solid var(--border-color);
  background-color: var(--bg-body);
  color: var(--text-secondary);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.lang-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.lang-btn.active {
  background-color: var(--brand-primary);
  color: #ffffff;
  border-color: var(--brand-primary);
}

/* ---- Utility classes ---- */
.muted {
  color: var(--text-muted);
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .app-shell {
    flex-direction: column;
  }

  .app-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
  }

  .sidebar-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .sidebar-section-label {
    display: none;
  }

  .sidebar-footer {
    display: none;
  }

  .app-main {
    padding: 1.5rem;
  }
}

@media (max-width: 768px) {
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .search-input {
    min-width: 100%;
    width: 100%;
  }

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

  .section-actions {
    width: 100%;
  }

  .page-header h1 {
    font-size: 1.5rem;
  }

  .kpi-value {
    font-size: 1.75rem;
  }

  .auth-card {
    padding: 1.5rem;
  }

  .auth-footer-secondary {
    flex-direction: column;
    text-align: center;
  }
}
