/* HKFRS 16 Lease Calculator v1 - Dark theme, purple accents, Apple-style */

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #1a1a1a;
  --bg-elevated: #252525;
  --text-primary: #f5f5f5;
  --text-secondary: #a0a0a0;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-muted: rgba(139, 92, 246, 0.2);
  --border: rgba(255, 255, 255, 0.08);
  --error: #ef4444;
  --radius: 10px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

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

/* Header */
.header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* User Guide (collapsible) */
.user-guide-details {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.user-guide-toggle {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
}

.user-guide-toggle:hover {
  color: var(--accent-hover);
}

.user-guide-content {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.user-guide-content ol {
  margin: 0 0 12px 0;
  padding-left: 20px;
}

.user-guide-content li {
  margin-bottom: 4px;
}

.user-guide-content a {
  color: var(--accent);
  text-decoration: none;
}

.user-guide-content a:hover {
  text-decoration: underline;
}

/* Main layout */
.main-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.sidebar {
  flex-shrink: 0;
  width: 220px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.sidebar-section label,
.sidebar-section .sidebar-heading {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.sidebar-section .sidebar-heading {
  font-size: 1.1rem;
}

.sidebar-section input,
.sidebar-section select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='%23a0a0a0'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.sidebar-section select:focus {
  outline: none;
  border-color: var(--accent);
}

.sidebar-section select {
  min-width: 0;
  text-overflow: ellipsis;
}

.content {
  flex: 1;
  min-width: 0;
}

.input-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
}

.input-section h2 {
  font-size: 1.1rem;
  margin-bottom: 20px;
  color: var(--text-primary);
}

/* Hide number input spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

.btn-calculate {
  margin-top: 24px;
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

.bulk-upload {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.file-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-name {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
  max-width: 700px;
}

.bulk-table-wrap {
  overflow-x: auto;
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bulk-table-wrap table {
  width: 100%;
  min-width: 1200px;
}

.bulk-table-wrap th:nth-child(1),
.bulk-table-wrap td.lease-name-cell {
  min-width: 180px;
}

.bulk-table-wrap th:nth-child(3),
.bulk-table-wrap th:nth-child(4) {
  min-width: 110px;
}

.breakdown-block td.lease-name-cell {
  min-width: 180px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bulk-table-wrap td.rent-free-cell {
  min-width: 90px;
}

.bulk-table-wrap td.rent-free-cell input {
  min-width: 60px;
}

.results-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.edit-hint-block {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: -8px;
  margin-bottom: 20px;
}

.lease-schedule .edit-hint {
  font-size: 0.75rem;
  font-weight: normal;
  color: var(--text-secondary);
}

.lease-schedule .payment-edit {
  width: 90px;
  padding: 6px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
}

#addRowBtn {
  margin-top: 12px;
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 12px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.bulk-table-wrap td input,
.bulk-table-wrap td select {
  width: 100%;
  min-width: 90px;
  padding: 8px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.85rem;
}

.bulk-table-wrap td select {
  min-width: 100px;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12' fill='%23a0a0a0'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.term-display {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 8px 10px;
}

.btn-remove {
  padding: 6px 12px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.btn-remove:hover {
  color: var(--error);
  border-color: var(--error);
}

.results-section {
  margin-top: 32px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.results-header h2 {
  font-size: 1.25rem;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.card {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, var(--bg-card) 100%);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}

.table-section {
  margin-bottom: 32px;
}

.table-section h3 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-scroll table {
  min-width: 900px;
}

.table-scroll td {
  white-space: nowrap;
}

/* Breakdown section - one table, multiple sections */
.breakdown-section .breakdown-block {
  margin-bottom: 24px;
}

.breakdown-section .breakdown-block h4 {
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.breakdown-section .table-scroll {
  margin-bottom: 8px;
}

.schedule-section {
  margin-top: 32px;
}

.schedule-section h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.lease-schedule {
  margin-bottom: 32px;
  padding: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lease-schedule h4 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  max-width: 400px;
  box-shadow: var(--shadow);
  z-index: 1000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: rgba(239, 68, 68, 0.95);
  color: white;
}

.toast.success {
  background: rgba(34, 197, 94, 0.95);
  color: white;
}

@media (max-width: 1024px) {
  .main-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }
  .bulk-upload {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Legal disclaimer */
.legal-disclaimer {
  margin-top: 48px;
  padding: 20px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.legal-disclaimer p {
  margin: 0;
}

.legal-disclaimer strong {
  color: var(--text-primary);
}
