* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  color: #e2e8f0;
  min-height: 100vh;
}

a {
  color: #38bdf8;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-header {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 1.1rem;
}

.header-account {
  display: inline-flex;
}

.header-account select {
  padding: 6px 10px;
  font-size: 0.9rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 8px;
  color: #e2e8f0;
  cursor: pointer;
  min-width: 140px;
}

.header-account select:hover,
.header-account select:focus {
  border-color: #38bdf8;
  outline: none;
}

.nav a {
  margin-left: 20px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.nav a:hover {
  color: #38bdf8;
  text-decoration: none;
}

.container {
  padding: 24px 28px;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  background: rgba(30, 41, 59, 0.6);
  padding: 20px 24px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  margin-bottom: 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.card.small {
  max-width: 460px;
  margin: 40px auto;
}

.config-page {
  max-width: 560px;
}

.config-title {
  margin: 0 0 24px 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #f1f5f9;
}

.config-section {
  background: rgba(30, 41, 59, 0.6);
  padding: 20px 24px;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  margin-bottom: 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.config-section:last-child {
  margin-bottom: 0;
}

.config-heading {
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
  color: #e2e8f0;
}

.config-desc {
  margin: -4px 0 12px 0;
  font-size: 0.9rem;
}

.config-form {
  margin-bottom: 16px;
}

.config-section .table-row.cols-3 {
  grid-template-columns: 1fr minmax(90px, auto) 80px;
}

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

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.grid.three {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

/* Dashboard: form top, journal below */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card-form h2,
.card-journal h2 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #f1f5f9;
}

.card-form {
  flex-shrink: 0;
  padding-bottom: 24px;
}

.card-journal {
  flex: 1;
  min-height: 0;
}

.journal-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.journal-header-row .journal-title {
  margin: 0;
  font-size: 1.1rem;
}

.journal-header-row .journal-account {
  font-size: 0.9rem;
  margin-left: auto;
}

.journal-header-row .filter-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.journal-header-row .filter-inline .filter-label {
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: nowrap;
}

.journal-header-row .filter-inline input[type="date"],
.journal-header-row .filter-inline select {
  padding: 4px 8px;
  font-size: 0.85rem;
}

.journal-header-row .filter-inline select {
  min-width: 100px;
}

.journal-preview-header {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.journal-preview-header .journal-title {
  margin: 0;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.journal-preview-header .journal-account {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.journal-link {
  margin-left: auto;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.journal-filters-single .journal-filters-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.journal-filters-row .journal-title {
  margin: 0;
  font-size: 1rem;
  flex-shrink: 0;
  margin-right: 20px;
}

.journal-filters-row .filter-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  flex-shrink: 0;
}

.journal-filters-row .filter-inline .filter-label {
  font-size: 0.7rem;
  color: #94a3b8;
  white-space: nowrap;
}

.journal-filters-row .filter-inline input[type="date"],
.journal-filters-row .filter-inline input[type="number"],
.journal-filters-row .filter-inline select {
  padding: 3px 6px;
  font-size: 0.75rem;
  width: auto;
  min-width: 0;
}

.journal-filters-row .filter-inline input[type="date"] {
  width: 98px;
}

.journal-filters-row .filter-inline input[type="number"] {
  width: 52px;
}

.journal-filters-row .filter-inline select {
  min-width: 72px;
}

.journal-filters-row .journal-account {
  font-size: 0.8rem;
  margin-left: auto;
  flex-shrink: 0;
}

.journal-filters-row .btn-apply,
.journal-filters-row button[type="submit"] {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.8rem;
  margin-right: 8px;
}

.journal-filters {
  margin-bottom: 16px;
}

.filter-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px 10px;
}

.journal-filters .filter-row {
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-row .filter-label {
  font-size: 0.8rem;
  color: #94a3b8;
  margin: 0;
  flex-shrink: 0;
}

.filter-row input[type="date"],
.filter-row input[type="number"],
.filter-row select {
  padding: 4px 8px;
  font-size: 0.85rem;
  min-width: 0;
  flex-shrink: 0;
}

.filter-row input[type="date"] {
  width: 130px;
}

.filter-row input[type="number"] {
  width: 78px;
  max-width: 78px;
}

.filter-row select {
  min-width: 90px;
}

.filter-row button[type="submit"] {
  flex-shrink: 0;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 0.9rem;
}

.pagination-info {
  color: #94a3b8;
}

.pagination-disabled {
  color: #64748b;
  cursor: default;
}

a.view-img-link {
  color: #38bdf8;
  text-decoration: underline;
}

a.view-img-link:hover {
  color: #7dd3fc;
}

/* Lightbox: click View → full-size image overlay, no new tab */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.85);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.img-lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

.img-lightbox__backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  cursor: pointer;
}

.img-lightbox__inner {
  position: relative;
  z-index: 1;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.img-lightbox__inner .img-lightbox__img,
.img-lightbox__inner .img-lightbox__actions {
  pointer-events: auto;
}

.img-lightbox__img {
  max-width: 95vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.img-lightbox__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.img-lightbox__close,
.img-lightbox__open-tab {
  padding: 8px 16px;
  font-size: 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  transition: background 0.15s, border-color 0.15s;
}

.img-lightbox__close:hover,
.img-lightbox__open-tab:hover {
  background: rgba(51, 65, 85, 0.95);
  border-color: #38bdf8;
}

.img-lightbox__open-tab {
  color: #38bdf8;
}

/* Compact 2-row form */
.form-compact {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-compact .form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
}

.form-compact .form-row-2 {
  padding-top: 4px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
}

.form-compact .form-row-notes-save {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 12px 16px;
}

.form-compact .form-row-notes-save .field-image,
.form-compact .form-row-notes-save .field-reason {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.form-compact .form-row-notes-save .field-image {
  flex: 0 1 35%;
  max-width: 280px;
  min-width: 140px;
  align-self: stretch;
}

.form-compact .form-row-notes-save .field-image .field-label,
.form-compact .form-row-notes-save .field-reason .field-label {
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  line-height: 1.2;
  min-height: 1.2em;
}

.form-compact .form-row-notes-save .field-image .image-upload-box {
  flex: 1;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.form-compact .form-row-notes-save .field-reason {
  flex: 0 1 35%;
  max-width: 280px;
  min-width: 140px;
  align-self: stretch;
}

.form-compact .form-row-notes-save .field-reason textarea {
  flex: 1;
  min-height: 100px;
  resize: vertical;
}

.form-compact .form-row-notes-save .field-save {
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  align-self: flex-start;
  padding-top: 1.6em;
}

.form-compact .field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.form-compact .field span,
.form-compact .field .field-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-compact .field input,
.form-compact .field select {
  padding: 6px 8px;
  font-size: 0.88rem;
  width: 100%;
  min-width: 52px;
  max-width: 96px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  color: #e2e8f0;
}

.form-compact .field input::placeholder {
  color: #64748b;
}

.form-compact .field input:focus,
.form-compact .field select:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.form-compact .field-pnl output {
  max-width: 96px;
  min-width: 80px;
}

.form-compact .field-symbol input {
  max-width: 68px;
  min-width: 56px;
}

.form-compact .field-qty input {
  max-width: 60px;
  min-width: 52px;
}

.form-compact .field-buy input,
.form-compact .field-sold input {
  max-width: 88px;
  min-width: 72px;
}

.form-compact .field-reason textarea {
  padding: 8px 10px;
  font-size: 0.9rem;
  font-family: inherit;
  min-height: 4.5em;
  resize: vertical;
  width: 100%;
  min-width: 0;
  max-width: none;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  color: #e2e8f0;
}

.form-compact .field-reason textarea::placeholder {
  color: #64748b;
}

.form-compact .field-reason textarea:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.form-compact .field-hint {
  font-size: 0.85rem;
  margin-left: 2px;
  text-decoration: none;
}

.form-compact .field-hint:hover {
  text-decoration: underline;
}

.image-upload-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-upload-box {
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.3);
}

.image-upload-box .paste-zone {
  border-color: rgba(148, 163, 184, 0.25);
}

.paste-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.paste-zone:hover,
.paste-zone:focus {
  border-color: #38bdf8;
  background: rgba(15, 23, 42, 0.7);
}

.paste-zone-text {
  font-size: 0.85rem;
  color: #94a3b8;
}

.paste-zone .paste-preview {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
  border-radius: 6px;
}

.file-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-upload-label {
  font-size: 0.85rem;
  color: #94a3b8;
  cursor: pointer;
}

.image-upload-wrap input[type="file"] {
  max-width: 200px;
  font-size: 0.8rem;
  padding: 4px 6px;
}

.file-selected {
  font-size: 0.8rem;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.form-row label {
  min-width: 0;
}

.pnl-preview {
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.5);
  display: inline-block;
  font-size: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.pnl-preview.positive { color: #4ade80; }
.pnl-preview.negative { color: #f87171; }

.small { font-size: 0.85rem; }

.form-footer {
  margin: 10px 0 0 0;
  font-size: 0.8rem;
}

.table-wrap {
  overflow-x: auto;
}

.form-inline {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.form-inline select {
  padding: 6px 10px;
  font-size: 0.9rem;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  color: #e2e8f0;
}

.table-row .form-inline {
  margin: 0;
  display: inline-flex;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

input,
select,
textarea {
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.95rem;
  background: rgba(15, 23, 42, 0.5);
  color: #e2e8f0;
}

input::placeholder,
textarea::placeholder {
  color: #64748b;
}

button {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 600;
  background: #38bdf8;
  color: #0f172a;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  background: #7dd3fc;
}

.btn-save {
  flex-shrink: 0;
}

button.link {
  background: none;
  color: #38bdf8;
  padding: 0;
  font-size: 0.85rem;
}

button.link:hover {
  text-decoration: underline;
  background: none;
}

.table {
  width: 100%;
}

.table-row {
  display: grid;
  gap: 10px 14px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  font-size: 0.9rem;
  align-items: center;
}

.table-row.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

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

.table-row.cols-8 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.table-row.cols-13 {
  grid-template-columns: repeat(13, minmax(0, 1fr));
}

.table-journal .table-row.cols-13 {
  grid-template-columns: minmax(90px, 1fr) minmax(70px, 1fr) 52px 52px 52px 52px minmax(70px, 1fr) minmax(90px, 1fr) minmax(70px, 1fr) minmax(90px, 1fr) 44px minmax(100px, 1.5fr) 44px;
}

.table-row.header {
  font-weight: 600;
  font-size: 0.8rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding-bottom: 8px;
}

.table-row:last-child {
  border-bottom: none;
}

.positive {
  color: #4ade80;
  font-weight: 600;
}

.negative {
  color: #f87171;
  font-weight: 600;
}

.flash-stack {
  margin-bottom: 16px;
}

.flash {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 0.9rem;
}

.flash.success {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.flash.error {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.muted {
  color: #94a3b8;
}

.wrap {
  word-break: break-word;
}

@media (max-width: 900px) {
  .table-row:not(.cols-13) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }
  .form-compact .field input,
  .form-compact .field select {
    max-width: none;
  }
}
