/* --- ROOT DESIGN VARIABLES --- */
:root {
  --primary-color: #2a6f4d; /* Xanh lá sầu riêng */
  --primary-dark: #1e5237;
  --primary-light: #e8f5e9;
  --accent-color: #f5b041; /* Vàng cơm sầu riêng chín */
  --accent-dark: #d35400;
  --accent-light: #fef5e7;
  --bg-app: #f5f7f6; /* Nền xám nhạt ấm áp */
  --bg-card: #ffffff;
  --text-main: #2c3e50; /* Chữ tối rõ ràng */
  --text-muted: #7f8c8d;
  --border-color: #e2e8f0;

  --success-color: #27ae60; /* Màu khi có lãi */
  --success-bg: #e8f8f5;
  --danger-color: #e74c3c; /* Màu khi lỗ */
  --danger-bg: #fdebd0;
  --warning-color: #f39c12; /* Màu cảnh báo */

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

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

body {
  font-family:
    "Outfit",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  padding: 20px 10px;
}

@media (min-width: 768px) {
  body {
    padding: 40px 20px;
  }
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
}

/* --- HEADER --- */
.app-header {
  text-align: center;
  margin-bottom: 30px;
  padding: 0 10px;
}

.header-banner {
  width: 100%;
  height: 460px;
  border-radius: 15px;
  margin-bottom: 1rem;
}

.header-banner img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: inherit;
}

.header-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo-icon {
  font-size: 1.8rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.app-header h1 {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary-dark);
  letter-spacing: -0.5px;
}

.header-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

@media (min-width: 768px) {
  .app-header h1 {
    font-size: 2.2rem;
  }
}

/* --- LAYOUT GRID --- */
.app-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

@media (min-width: 992px) {
  .app-content {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: start;
  }
}

.left-column,
.right-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* --- CARD COMPONENT --- */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition:
    transform var(--transition-normal),
    box-shadow var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  background-color: #fafbfc;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.card-body {
  padding: 20px;
  overflow: hidden;
  overflow-y: auto;
}

/* Toggle collapsible card */
.toggle-btn {
  border: none;
  cursor: pointer;
  background: none;
  outline: none;
  transition: background-color var(--transition-fast);
}

.toggle-btn:hover {
  background-color: #f1f5f9;
}

.toggle-icon {
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: transform var(--transition-normal);
}

.toggle-btn[aria-expanded="false"] .toggle-icon {
  transform: rotate(-90deg);
}

/* Collapsible body container */
#settings-body,
#results-body {
  transition:
    max-height var(--transition-normal) ease-out,
    opacity var(--transition-normal);
  overflow: hidden;
}

/* --- INPUTS & FORM CONTROLS --- */
.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-main);
  font-size: 0.95rem;
}

/* Input standard styles */
input[type="number"] {
  font-family: inherit;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 1rem;
  color: var(--text-main);
  outline: none;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
  width: 100%;
}

input[type="number"]:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(42, 111, 77, 0.15);
}

/* Input with unit badge */
.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-unit input {
  padding-right: 90px; /* space for badge */
}

.unit-badge {
  position: absolute;
  right: 1.5px;
  top: 1.5px;
  bottom: 1.5px;
  background-color: #f1f5f9;
  color: var(--text-main);
  padding: 0 14px;
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
  border-left: 1.5px solid var(--border-color);
  border-top-right-radius: calc(var(--radius-sm) - 1.5px);
  border-bottom-right-radius: calc(var(--radius-sm) - 1.5px);
  pointer-events: none;
}

/* --- BUTTONS --- */
.btn {
  font-family: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
}

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

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

.btn-secondary {
  background-color: #f1f5f9;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #e2e8f0;
}

.btn-accent {
  background-color: var(--accent-color);
  color: #3b2a0c;
}

.btn-accent:hover {
  background-color: #f39c12;
  transform: translateY(-1px);
}

.btn-danger {
  background-color: #fde8e8;
  color: var(--danger-color);
  border: 1px solid #fbd5d5;
}

.btn-danger:hover {
  background-color: #fbd5d5;
}

.btn-large {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 10px rgba(245, 176, 65, 0.3);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 6px;
}

/* --- SEGMENTED CONTROL (Varying Options) --- */
.segmented-control {
  display: flex;
  background-color: #f1f5f9;
  border-radius: var(--radius-md);
  padding: 4px;
  border: 1px solid var(--border-color);
}

.segmented-control input[type="radio"] {
  display: none;
}

.segment-label {
  flex: 1;
  text-align: center;
  padding: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  color: var(--text-muted);
}

.segmented-control input[type="radio"]:checked + .segment-label {
  background-color: var(--bg-card);
  color: var(--primary-color);
  box-shadow: var(--shadow-sm);
}

/* --- RATIO OPTIONS BUTTONS --- */
.ratio-options-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.ratio-options-group input[type="radio"] {
  display: none;
}

.ratio-btn {
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  background-color: var(--bg-card);
  color: var(--text-main);
}

.ratio-options-group input[type="radio"]:checked + .ratio-btn {
  border-color: var(--primary-color);
  background-color: var(--primary-light);
  color: var(--primary-color);
  font-weight: 700;
}

.custom-ratio-container {
  margin-top: 10px;
  padding: 12px;
  background-color: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-color);
  animation: fadeIn var(--transition-fast);
}

.helper-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

/* --- SETTINGS CARD SPECIFICS --- */
.settings-group {
  margin-bottom: 20px;
}

.settings-group h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  border-left: 3px solid var(--primary-color);
  padding-left: 8px;
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
}

.settings-table th,
.settings-table td {
  padding: 8px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.settings-table th:first-child,
.settings-table td:first-child {
  text-align: left;
}

.settings-table th {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.type-label {
  font-weight: 600;
  color: var(--text-main);
  font-size: 0.9rem;
}

.input-inline {
  width: 90px !important;
  padding: 6px 10px !important;
  font-size: 0.9rem !important;
  text-align: right;
}

.input-small {
  width: 70px !important;
  padding: 6px 10px !important;
  font-size: 0.9rem !important;
  text-align: right;
}

.input-medium {
  width: 110px !important;
  padding: 6px 10px !important;
  font-size: 0.9rem !important;
  text-align: right;
}

.input-flex {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.input-flex label {
  font-size: 0.85rem;
  color: var(--text-main);
}

.input-flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.input-flex-between label {
  font-size: 0.85rem;
}

.proportion-inputs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.prop-subgroup {
  background-color: #fafbfc;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.subgroup-title {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.costs-inputs {
  background-color: #fafbfc;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.cost-summary {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-color);
}

.settings-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 10px 0;
}

.settings-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  gap: 12px;
}

.settings-actions button {
  flex: 1;
}

.alert-warning-text {
  color: var(--danger-color);
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 4px;
  text-align: right;
  animation: fadeIn var(--transition-fast);
}

/* Collapsible layout settings */
@media (min-width: 576px) {
  .settings-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .proportion-inputs {
    height: 100%;
    justify-content: start;
  }
}

/* --- RESULTS SECTION SPECIFICS --- */
.results-header-flex {
  flex-wrap: wrap;
  gap: 12px;
}

.calc-timestamp-wrapper {
  background-color: #fafbfc;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-color);
  margin-bottom: 20px;
  color: var(--text-main);
  font-weight: 500;
}

.clock-icon {
  font-size: 1rem;
}

.results-subgroup {
  margin-bottom: 24px;
}

.subgroup-heading {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 12px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th,
.results-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.95rem;
}

.results-table th {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  background-color: #fafbfc;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.font-weight-bold {
  font-weight: 700;
}

.font-weight-medium {
  font-weight: 500;
}

.table-total-row td {
  font-weight: 800;
  color: var(--primary-dark);
  background-color: var(--primary-light);
  border-top: 2px solid var(--primary-color);
}

.results-panel-box {
  background-color: #fafbfc;
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
  height: 100%;
}

.cost-details-list,
.metrics-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cost-details-list li,
.metrics-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.cost-details-list li span,
.metrics-list li span {
  color: var(--text-muted);
}

.cost-details-list li strong,
.metrics-list li strong {
  color: var(--text-main);
  font-weight: 700;
}

.cost-details-list li.divider,
.metrics-list li.divider {
  border-bottom: 1px dashed var(--border-color);
  margin: 4px 0;
}

.cost-details-list li.highlight-row,
.metrics-list li.highlight-row {
  font-size: 0.95rem;
}

.cost-details-list li.highlight-row strong,
.metrics-list li.highlight-row strong {
  color: var(--primary-dark);
}

.color-primary {
  color: var(--primary-color) !important;
}

.color-warning {
  color: var(--warning-color) !important;
}

.profit-loss-item {
  flex-direction: column !important;
  gap: 8px;
  margin-top: 10px;
}

.p-l-label {
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.profit-loss-badge-wrapper {
  width: 100%;
}

.badge {
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.badge-profit {
  background-color: var(--success-bg);
  color: var(--success-color);
  border: 2px solid var(--success-color);
}

.badge-loss {
  background-color: #fdf2f2;
  color: var(--danger-color);
  border: 2px solid var(--danger-color);
}

.badge-even {
  background-color: var(--bg-app);
  color: var(--text-main);
  border: 2px solid var(--border-color);
}

@media (min-width: 576px) {
  .results-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

/* --- HISTORY SECTION SPECIFICS --- */
.history-header-flex {
  justify-content: space-between;
  align-items: center;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 12px;
}

.empty-state p {
  font-weight: 600;
  font-size: 1rem;
}

.empty-state .sub-text {
  font-size: 0.85rem;
  font-weight: 400;
  margin-top: 4px;
}

/* Timeline Layout */
.history-timeline {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.history-day-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-date-header {
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--primary-dark);
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--primary-light);
  padding-bottom: 4px;
  margin-top: 10px;
}

/* History Card Item */
.history-item {
  background-color: #fafbfc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.history-item:hover {
  border-color: var(--primary-color);
  background-color: #fffdf9;
  transform: translateX(3px);
}

.history-item-left {
  border-left: 4px solid var(--border-color);
}

.history-item-profit {
  border-left: 4px solid var(--success-color);
}

.history-item-loss {
  border-left: 4px solid var(--danger-color);
}

/* History Grid Inside Card */
.history-item-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-item-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.history-item-badge {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 4px 10px;
  border-radius: 6px;
}

.badge-text-profit {
  color: var(--success-color);
  background-color: var(--success-bg);
}

.badge-text-loss {
  color: var(--danger-color);
  background-color: #fdf2f2;
}

.badge-text-even {
  color: var(--text-main);
  background-color: #f1f5f9;
}

/* Action section on hover */
.history-item-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-delete-item {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.95rem;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}

.btn-delete-item:hover {
  color: var(--danger-color);
  background-color: #fde8e8;
}

/* Responsive Table Wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- PAGINATION CONTROLS --- */
.pagination-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--border-color);
}

.page-info {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
}

/* --- TOAST NOTIFICATION --- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: #2c3e50;
  color: white;
  padding: 12px 24px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition:
    transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    opacity 0.3s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* --- APP FOOTER --- */
.app-footer {
  text-align: center;
  margin-top: 40px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* --- KEYFRAMES --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .header-banner {
    height: 360px;
  }

  .settings-actions {
    flex-direction: column;
  }
}
