:root {
  --bg-app: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-sidebar: #1a202c;
  --text-main: #1a202c;
  --text-muted: #718096;
  --text-inv: #e2e8f0;

  --border-subtle: #e2e8f0;
  --border-focus: #3182ce;

  --accent-primary: #3182ce;
  --accent-success: #059669;
  --accent-warning: #d97706;
  --accent-danger: #e53e3e;
  --accent-disabled: #cbd5e0;

  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --radius-sm: 4px;
  --radius-md: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text-main);
  background: var(--bg-app);
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  color: var(--text-inv);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.main-content {
  overflow-y: auto;
  padding: 2rem;
  background: var(--bg-app);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.module-panel {
  position: relative;
  background: #fff;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.5rem 0.25rem;
  margin-bottom: 1.25rem;
}

.module-panel::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 4px;
  border-radius: 10px 10px 0 0;
}

.module-keys::before {
  background: linear-gradient(90deg, #2563eb, #1d4ed8);
}

.module-sign::before {
  background: linear-gradient(90deg, #0f766e, #0d9488);
}

.module-verify::before {
  background: linear-gradient(90deg, #0ea5e9, #0369a1);
}

h1 {
  margin: 0 0 0.5rem 0;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

h2 {
  margin: 0 0 0.5rem 0;
  font-weight: 600;
  font-size: 1.1rem;
}

h3 {
  margin: 0 0 0.75rem 0;
  font-weight: 600;
  font-size: 1rem;
}

h4 {
  margin: 0 0 0.5rem 0;
  font-weight: 600;
  font-size: 0.95rem;
}

.subtitle {
  margin: 0 0 2rem 0;
  font-size: 0.85rem;
  color: #a0aec0;
  line-height: 1.4;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(148, 163, 184, 0.24);
  color: #a0aec0;
  padding: 0.75rem 1rem;
  text-align: left;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border-color: rgba(148, 163, 184, 0.45);
}

.nav-item.active {
  background: rgba(49, 130, 206, 0.22);
  color: #93c5fd;
  border-color: rgba(96, 165, 250, 0.65);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.22);
}

.nav-item .icon {
  width: 1.1rem;
  text-align: center;
}

.security-context {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1.5rem;
  font-size: 0.8rem;
}

.context-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  color: #a0aec0;
  gap: 0.75rem;
}

.context-val {
  font-family: var(--font-mono);
  color: white;
  text-align: right;
  word-break: break-all;
}

.context-val.status-success {
  color: var(--accent-success);
}

.context-val.status-warning {
  color: var(--accent-warning);
}

.context-val.status-muted {
  color: var(--text-muted);
}

.status-line {
  display: inline-flex;
  align-items: center;
}

.status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--text-muted);
}

.status-indicator.secure {
  background: var(--accent-success);
  box-shadow: 0 0 8px rgba(5, 150, 105, 0.4);
}

.status-indicator.warning {
  background: var(--accent-warning);
}

.status-indicator.danger {
  background: var(--accent-danger);
}

.sidebar-note {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: #718096;
  line-height: 1.4;
}

.sidebar-selftest {
  margin-top: 0.6rem;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(255, 255, 255, 0.06);
  color: #dbeafe;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.sidebar-selftest:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-selftest:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.section-header {
  margin-bottom: 1.25rem;
}

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

.full-width {
  grid-column: 1 / -1;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.diagnostics-panel {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: #fff;
}

.diagnostics-summary {
  cursor: pointer;
  padding: 0.65rem 0.8rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  list-style: none;
}

.diagnostics-summary::-webkit-details-marker {
  display: none;
}

.diagnostics-summary::after {
  content: 'v';
  float: right;
  font-family: var(--font-mono);
}

.diagnostics-panel:not([open]) .diagnostics-summary::after {
  content: '>';
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

input[type='text'],
input[type='password'],
input[type='file'],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  background: #fff;
  transition: border-color 0.15s;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.1);
}

.form-group {
  margin-bottom: 1rem;
}

.button-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.button-group.compact {
  gap: 0.5rem;
}

.no-margin {
  margin: 0;
}

button {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}

button.primary {
  background: var(--accent-primary);
  color: white;
}

button.primary:hover:not(:disabled) {
  background: #2b6cb0;
}

button.secondary {
  background: white;
  border-color: var(--border-subtle);
  color: var(--text-main);
}

button.secondary:hover:not(:disabled) {
  border-color: #cbd5e0;
  background: #f7fafc;
}

button.danger {
  background: white;
  border-color: var(--accent-danger);
  color: var(--accent-danger);
}

button.danger:hover:not(:disabled) {
  background: #fff5f5;
}

button.small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.mono-box {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  background: #f7fafc;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  overflow-x: auto;
  white-space: pre-wrap;
  color: #2d3748;
}

.radio-row {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.radio-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.9rem;
  color: var(--text-main);
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.no-bottom {
  margin-bottom: 0;
}

.muted-copy {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0;
}

.hint-warning {
  margin-top: 0.5rem;
  color: var(--accent-warning);
  font-size: 0.85rem;
}

.hash-progress {
  margin-top: 1rem;
  width: 100%;
}

.progress-label {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

.result-card {
  border-left: 6px solid transparent;
}

.review-panel {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #fbfdff 0%, #f7fafc 100%);
}

.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.review-head h3 {
  margin: 0;
}

.review-copy {
  margin-bottom: 0.75rem;
}

.review-box {
  margin-top: 0;
}

.result-card.valid {
  border-left-color: var(--accent-success);
}

.result-card.invalid {
  border-left-color: var(--accent-danger);
}

.result-card.warning {
  border-left-color: var(--accent-warning);
}

.result-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.result-icon {
  font-size: 2rem;
  line-height: 1;
}

.result-main {
  flex: 1;
}

.result-heading {
  margin-bottom: 0.5rem;
}

.result-message {
  margin-top: 0;
  margin-bottom: 1rem;
  color: var(--text-main);
}

.result-caveat {
  margin-top: -0.25rem;
  margin-bottom: 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(217, 119, 6, 0.25);
  background: rgba(217, 119, 6, 0.08);
  color: #9a5b06;
  font-size: 0.88rem;
}

.details-box {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.keys-info-box {
  margin-top: 1rem;
  min-height: 120px;
}

.sign-card {
  max-width: 860px;
}

.sign-result {
  margin-top: 1rem;
}

.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  background: white;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--text-muted);
  font-size: 0.92rem;
  animation: slideIn 0.25s ease;
  max-width: 420px;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.fade-out {
  opacity: 0;
  transform: translateY(16px);
}

.toast.success {
  border-left-color: var(--accent-success);
}

.toast.error {
  border-left-color: var(--accent-danger);
}

.toast.warning {
  border-left-color: var(--accent-warning);
}

.toast.info {
  border-left-color: var(--accent-primary);
}

@keyframes slideIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    gap: 1rem;
  }

  .nav-menu {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .nav-item {
    flex: 1 1 130px;
    text-align: center;
  }

  .main-content {
    padding: 1rem;
  }

  .module-panel {
    padding: 1rem;
  }

  .panel-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .result-layout {
    flex-direction: column;
  }
}

.header-group {
  margin-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge.valid {
  color: var(--accent-success);
  border-color: rgba(5, 150, 105, 0.35);
  background: rgba(5, 150, 105, 0.08);
}

.badge.invalid {
  color: var(--accent-danger);
  border-color: rgba(229, 62, 62, 0.35);
  background: rgba(229, 62, 62, 0.08);
}

.badge.warning {
  color: var(--accent-warning);
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.08);
}

.badge.neutral {
  color: var(--text-muted);
  background: #f7fafc;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.result-heading {
  margin: 0;
}

.result-heading.valid {
  color: var(--accent-success);
}

.result-heading.invalid {
  color: var(--accent-danger);
}

.result-heading.warning {
  color: var(--accent-warning);
}
