:root {
  --bg: #0d0f12;
  --panel: #171a20;
  --panel-soft: #12151a;
  --field: #0f1217;
  --text: #edf0f4;
  --muted: #9aa3af;
  --line: #2a3038;
  --accent: #c7a15a;
  --accent-dark: #aa8441;
  --accent-soft: #272013;
  --danger: #f07d7d;
  --danger-bg: #2a1517;
  --top: #080a0d;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(199, 161, 90, 0.06), transparent 360px),
    linear-gradient(180deg, #11151b 0, var(--bg) 420px),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 14px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #15110a;
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
  line-height: 1;
  min-height: 40px;
  font-weight: 800;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
.file-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: 0 8px 22px rgba(199, 161, 90, 0.12);
}

button:active,
.file-button:active {
  transform: translateY(1px);
}

button:disabled {
  border-color: #303640;
  background: #222832;
  color: #6f7885;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.danger {
  border-color: #743234;
  background: var(--danger-bg);
  color: var(--danger);
  box-shadow: none;
}

button.danger:hover:not(:disabled) {
  border-color: #9f3d3f;
  background: #35191b;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--field);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

textarea {
  resize: vertical;
  min-height: 120px;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(199, 161, 90, 0.16);
}

input:disabled,
textarea:disabled,
select:disabled {
  background: #171a20;
  color: #707987;
}

label {
  color: #d8dde5;
  font-weight: 800;
}

code {
  background: var(--accent-soft);
  color: #e2c98f;
  border-radius: 5px;
  padding: 2px 6px;
  font-weight: 800;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 78px;
  padding: 16px 24px;
  background:
    linear-gradient(135deg, rgba(199, 161, 90, 0.08), transparent 46%),
    var(--top);
  color: var(--text);
  border-bottom: 1px solid rgba(199, 161, 90, 0.14);
}

.brand,
.login-brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(145deg, #d1ac63, #806235);
  color: #14100a;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: none;
}

.topbar h1,
.topbar p,
.section-head h2,
.section-head p,
.login-box h2,
.login-box p {
  margin: 0;
}

.topbar h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions button,
.top-actions .file-button {
  min-height: 36px;
  padding: 9px 12px;
  box-shadow: none;
}

.user-badge {
  color: #ead7a4;
  font-weight: 800;
  background: rgba(199, 161, 90, 0.1);
  border: 1px solid rgba(199, 161, 90, 0.24);
  border-radius: 999px;
  padding: 8px 11px;
}

.login-panel {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 78px);
  padding: 24px;
}

.login-box,
.password-box {
  display: grid;
  gap: 16px;
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.login-box h2,
.password-box h2 {
  font-size: 22px;
}

.login-box p,
.password-box p {
  color: var(--muted);
}

.login-box label,
.password-box label {
  display: grid;
  gap: 8px;
}

#loginStatus,
#passwordStatus {
  color: var(--danger);
  min-height: 18px;
}

.password-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 6, 8, 0.76);
}

.password-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.file-button {
  display: inline-flex;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  background: rgba(23, 26, 32, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(8px);
}

.company-panel {
  grid-row: span 2;
  align-self: start;
  position: sticky;
  top: 14px;
}

.output-panel {
  grid-column: 2;
}

.activity-panel {
  grid-column: 2;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.section-head p {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.45;
}

.row-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.form-actions .danger {
  min-width: 150px;
}

.company-list,
.mini-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.company-item,
.mini-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  padding: 10px;
}

.company-item {
  display: grid;
  gap: 5px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.company-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.company-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.company-name {
  font-weight: 850;
}

.company-counts,
.mini-meta {
  color: var(--muted);
  font-size: 12px;
}

.mini-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.mini-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.mini-actions {
  display: flex;
  gap: 6px;
}

.mini-actions button {
  min-height: 32px;
  padding: 7px 9px;
}

.activity-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.activity-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  padding: 10px;
}

.grid {
  display: grid;
  gap: 16px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.tab-button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  min-height: 38px;
  padding: 8px 12px;
  box-shadow: none;
}

.tab-button:hover {
  background: var(--panel-soft);
  color: var(--text);
  box-shadow: none;
}

.tab-button.active {
  border-bottom-color: var(--accent);
  color: #e2c98f;
  background: transparent;
}

.tab-panel {
  display: none;
}

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

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

.stack {
  display: grid;
  align-content: start;
  gap: 10px;
}

.saved-box,
.bulk-box {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 13px;
  margin-top: 10px;
}

.saved-box h3 {
  margin: 0;
  font-size: 14px;
}

.saved-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.saved-title-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: min(520px, 70%);
}

.saved-title-actions input {
  max-width: 260px;
  min-width: 220px;
}

.saved-title-actions button {
  min-height: 32px;
  padding: 7px 9px;
  white-space: nowrap;
}

.saved-box .mini-list {
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

#linkList {
  max-height: none;
  overflow: visible;
}

.generate-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.generate-grid label {
  display: grid;
  gap: 8px;
}

.generate-grid button {
  min-height: 44px;
  margin-top: 25px;
}

.result-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  margin: 14px 0;
}

.result-meta span {
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 999px;
  padding: 7px 10px;
  font-weight: 800;
}

.saved-search {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}

.saved-search .mini-list {
  max-height: none;
  overflow: visible;
}

.saved-search .mini-item {
  min-height: 44px;
  padding: 8px 10px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.output-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

#statusText {
  color: #e2c98f;
  min-height: 20px;
  font-weight: 800;
}

.output-grid {
  align-items: stretch;
}

#outputHtml {
  min-height: 385px;
}

#previewFrame,
#templatePreviewFrame {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

#previewFrame {
  min-height: 385px;
}

#templatePreviewFrame {
  min-height: 260px;
}

.template-preview-box {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  background: var(--field);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.validation-box {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.validation-box .bad {
  color: var(--danger);
  font-weight: 800;
}

.validation-box .good {
  color: #e2c98f;
  font-weight: 800;
}

@media (max-width: 1100px) {
  .layout,
  .grid.two,
  .generate-grid {
    grid-template-columns: 1fr;
  }

  .company-panel,
  .output-panel,
  .activity-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .company-panel {
    position: static;
  }

  .generate-grid button {
    margin-top: 0;
  }
}

@media (max-width: 700px) {
  .topbar,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .saved-title-row,
  .saved-title-actions {
    align-items: stretch;
    flex-direction: column;
    min-width: 0;
  }

  .saved-title-actions input {
    max-width: none;
    min-width: 0;
  }

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

  .top-actions {
    align-items: stretch;
  }

  .top-actions button,
  .top-actions .file-button {
    justify-content: center;
  }
}
