:root {
  font-family: 'Noto Sans KR', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #0f172a;
  background-color: #f1f5f9;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f1f5f9;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem 1rem;
  background: #0f172a;
  color: rgba(255, 255, 255, 0.92);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-sizing: border-box;
}

.sidebar-brand {
  margin-bottom: 1.25rem;
}

.sidebar-brand-link {
  color: rgba(255, 255, 255, 0.94);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.86);
  text-decoration: none;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

.sidebar-link[aria-current="page"] {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(147, 197, 253, 0.35);
  color: rgba(255, 255, 255, 0.96);
}

.app-main {
  min-width: 0;
}

.top-right-auth {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
}

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  text-decoration: none;
  background: rgba(15, 23, 42, 0.06);
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.12);
  transition: background 0.2s ease, opacity 0.2s ease;
}

.small-button:hover {
  background: rgba(15, 23, 42, 0.1);
}

.admin-button {
  margin-top: 0.35rem;
  border-radius: 999px;
}

#root {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .top-right-auth {
    top: 74px;
  }

  .sidebar {
    height: auto;
    position: sticky;
    z-index: 40;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }

  .sidebar-brand {
    margin-bottom: 0;
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow: auto;
    padding-bottom: 0.15rem;
  }

  .sidebar-link {
    white-space: nowrap;
  }
}

header {
  margin-bottom: 1.5rem;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.35;
}

section {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.portfolio-date-row {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(340px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.25rem;
}

.portfolio-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 1rem;
  background: #fff;
}

.portfolio-card-header {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.portfolio-name {
  margin-top: 0;
  padding: 0.45rem 0.6rem;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  font-weight: 700;
  font-size: 1rem;
  min-width: 140px;
  flex: 1;
}

.portfolio-sum {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.portfolio-sum.ok {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.3);
  color: #166534;
}

.portfolio-sum.bad {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.28);
  color: #991b1b;
}

.portfolio-normalize {
  margin-top: 0;
  white-space: nowrap;
}

.portfolio-delete {
  margin-top: 0;
  white-space: nowrap;
}

.portfolio-holdings {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.holding-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px auto;
  gap: 0.75rem;
  align-items: end;
}

.holding-ticker {
  margin: 0;
}

.holding-weight {
  margin: 0;
}

.holding-remove {
  margin-top: 1.35rem;
  white-space: nowrap;
}

.portfolio-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.portfolio-actions button {
  margin-top: 0;
}

.portfolio-compare-actions {
  margin-top: 0.25rem;
}

.hint {
  color: #475569;
  font-size: 0.9rem;
}

.range-label {
  color: #475569;
  margin: 0.5rem 0 0;
}

@media (max-width: 600px) {
  .portfolio-grid {
    grid-template-columns: 1fr;
  }

  .holding-row {
    grid-template-columns: 1fr;
  }

  .holding-remove {
    margin-top: 0;
  }
}

@media (max-width: 820px) {
  .portfolio-grid {
    grid-template-columns: 1fr;
  }
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: #475569;
  position: relative;
}

select,
input:not([type="checkbox"]):not([type="radio"]) {
  margin-top: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #cbd5f5;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  border-radius: 4px;
}

button {
  margin-top: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  border: none;
  transition: opacity 0.2s ease;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:not(:disabled):hover {
  opacity: 0.9;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.actions-spacer {
  flex: 1;
}

.ghost-button {
  background: transparent;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.ghost-button:not(:disabled):hover {
  opacity: 1;
  background: rgba(59, 130, 246, 0.08);
}

.danger-button {
  margin-top: 0.35rem;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  cursor: pointer;
  background: transparent;
  color: #b91c1c;
  border: 1px solid rgba(239, 68, 68, 0.35);
  transition: background 0.2s ease, opacity 0.2s ease, border-color 0.2s ease;
}

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

.danger-button:not(:disabled):hover {
  opacity: 1;
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.55);
}

.chart-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.chart-toolbar label {
  width: auto;
  min-width: 160px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.metric-card {
  background: #0f172a;
  color: #fff;
  padding: 1rem;
  border-radius: 12px;
}

.metric-card h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 500;
}

.metric-card p {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.chart-wrapper {
  margin-top: 1rem;
}

.error-box {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-top: 1rem;
}

.table-container {
  overflow-x: auto;
  margin-top: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

table th,
table td {
  padding: 0.6rem;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

table th {
  background: #f8fafc;
  color: #475569;
}

.autocomplete-menu {
  position: absolute;
  z-index: 60;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
  overflow: hidden;
  max-height: 320px;
  display: flex;
  flex-direction: column;
}

.autocomplete-list {
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  overflow: auto;
}

.autocomplete-item {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: rgba(59, 130, 246, 0.08);
}

.autocomplete-item .ticker {
  font-variant-numeric: tabular-nums;
  color: #1f2937;
  font-weight: 600;
}

.autocomplete-item .name {
  color: #475569;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.autocomplete-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 0.9rem;
  color: #475569;
}

.autocomplete-footer a {
  color: #1d4ed8;
  text-decoration: none;
  font-weight: 600;
}

.autocomplete-footer a:hover {
  text-decoration: underline;
}

.tag-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.tag-section {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 0.85rem;
}

.tag-section h4 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  color: #0f172a;
}

.tag-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.35rem 0.75rem;
}

.tag-item {
  display: flex;
  flex-direction: row;
  gap: 0.35rem;
  align-items: center;
  color: #475569;
  font-size: 0.95rem;
  margin: 0;
}

.tag-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.tag-toolbar select {
  margin-top: 0;
}

.tag-panel {
  margin: 0 0 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #f8fafc;
  overflow: hidden;
}

.tag-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.tag-panel-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.tag-panel-body {
  padding: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(15, 23, 42, 0.12);
  font-size: 0.85rem;
  color: #0f172a;
}

.recommendations {
  margin-top: 1rem;
  border-top: 1px solid #e2e8f0;
  padding-top: 1rem;
}

.recommendations h4 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}

.recommendation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.5rem;
}

.recommendation-button {
  margin-top: 0;
  background: transparent;
  color: #0f172a;
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.recommendation-button:hover {
  background: rgba(59, 130, 246, 0.08);
  opacity: 1;
}

.recommendation-button .sub {
  color: #475569;
  font-size: 0.85rem;
}
