:root {
  /* Color Palette - Premium Light Mode */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #0f172a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --bg-input-hover: #e2e8f0;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --success: #10b981;
  --success-bg: #d1fae5;
  --error: #ef4444;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-glow: 0 0 15px 0 rgb(37 99 235 / 0.15);

  /* Radii */
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--secondary);
  letter-spacing: -0.025em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.header h1 svg {
  color: var(--primary);
  width: 24px;
  height: 24px;
}

/* Main Container */
.container {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 1rem;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background-color: var(--bg-card);
  padding: 0.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.tab-btn {
  flex: 1 1 calc(25% - 0.5rem);
  /* Minimum width roughly 4 items per row */
  min-width: 120px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.tab-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-input);
}

.tab-btn.active {
  color: var(--primary);
  background-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

/* Content Area */
.app-content {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

@media (max-width: 768px) {
  .app-content {
    flex-direction: column;
  }
}

/* Calculator Card */
.calc-card {
  flex: 2;
  background-color: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.calc-section {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.calc-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--secondary);
}

.material-selector {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.material-selector label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.density-box {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: -0.25rem;
}

.density-val {
  color: var(--primary);
  font-weight: 700;
}

select {
  padding: 0.5rem 2rem 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  appearance: none;
  outline: none;
  cursor: pointer;
  transition: all var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
}

select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input-group label span.unit {
  color: var(--text-muted);
  font-size: 0.75rem;
  background-color: var(--bg-input);
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.input-group>[type="number"] {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition);
}

.input-group>[type="number"]:focus {
  background-color: var(--bg-card);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group>[type="number"]:hover:not(:focus) {
  background-color: var(--bg-input-hover);
}

/* Button */
.btn-calc {
  width: 100%;
  padding: 0.875rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: white;
  background-color: var(--primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-calc:hover {
  background-color: var(--primary-hover);
  box-shadow: var(--shadow-glow);
}

.btn-calc:active {
  transform: translateY(1px);
}

/* --- Layout Overrides for History Panel --- */
.history-panel {
  flex: 1;
  background-color: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 320px;
  max-width: 400px;
  position: sticky;
  top: 2rem;
  height: auto;
  max-height: calc(100vh - 4rem);
  flex-shrink: 0;
  overflow: hidden;
}

@media (max-width: 768px) {
  .history-panel {
    max-width: 100%;
    position: relative;
    top: 0;
    height: auto;
    min-height: 400px;
  }
}

.history-header {
  padding: 1.5rem;
  background-color: var(--primary);
  color: white;
  border-bottom: 2px solid var(--primary-hover);
}

.history-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

.history-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: var(--bg-body);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 2rem 0;
  font-style: italic;
}

.history-footer {
  padding: 1.5rem;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-clear {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--transition);
}

.btn-clear:hover {
  color: var(--error);
}

.total-weight-box {
  text-align: right;
  background-color: var(--primary-light);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  color: var(--primary-hover);
}

.total-weight-box .total-value {
  font-size: 1.5rem;
  font-weight: 800;
}

.total-weight-box .total-unit {
  font-size: 0.875rem;
  font-weight: 600;
}

/* History Items */
.history-group {
  margin-bottom: 1rem;
}

.history-group-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  letter-spacing: 0.05em;
}

.history-item {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform var(--transition);
}

.history-item:hover {
  transform: translateX(-4px);
  border-color: var(--primary);
}

.history-item-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.history-item-specs {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-main);
}

.history-item-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.history-item-weight {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.history-item-weight strong {
  font-size: 1rem;
  font-weight: 700;
  color: var(--secondary);
}

.history-item-weight span {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.btn-delete-item {
  position: absolute;
  top: -8px;
  right: -8px;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--error);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.history-item:hover .btn-delete-item {
  opacity: 1;
}

.btn-delete-item:hover {
  transform: scale(1.1);
  background-color: var(--error);
  color: white;
  border-color: var(--error);
}

/* --- Form Actions & Adet Controls --- */
.form-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.adet-control {
  display: flex;
  align-items: stretch;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  height: 48px;
}

.adet-control button {
  background: transparent;
  border: none;
  width: 40px;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition);
}

.adet-control button:hover {
  background-color: var(--bg-input-hover);
  color: var(--text-main);
}

.adet-input-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  background-color: var(--bg-card);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.adet-input-wrapper .adet-label-text {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.adet-input-wrapper input {
  width: 40px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--secondary);
  outline: none;
  padding: 0;
}

/* Hide spin buttons for numbers */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.btn-calc {
  flex-grow: 1;
  height: 48px;
  padding: 0 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  font-family: inherit;
  color: white;
  background-color: var(--success);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-calc:hover {
  background-color: #059669;
  /* darker success */
  box-shadow: 0 4px 6px -1px rgb(16 185 129 / 0.3);
}

.btn-calc:active {
  transform: translateY(1px);
}

.btn-reset {
  height: 48px;
  padding: 0 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-reset:hover {
  background: var(--bg-input-hover);
  color: var(--secondary);
}

/* Visually Hidden Helper */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* --- Visual Guides Layout --- */
.calc-body {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

@media (max-width: 768px) {
  .calc-body {
    flex-direction: column;
  }
}

.visual-guide {
  flex: 0 0 250px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-body);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-height: 200px;
}

.visual-guide svg {
  width: 100%;
  height: auto;
  max-height: 200px;
}

.calc-form {
  flex: 1;
}