/* =============================
   Animations
   ============================= */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }

    100% {
        opacity: 1;
    }
}

.update-pulse {
    animation: pulse 0.4s ease-in-out;
}

/* =============================
   Root Variables
   ============================= */
:root {
    --primary: #2d3436;
    --primary-light: #3d4a54;
    --secondary: #d97706;
    --accent: #92400e;
    --accent-light: #b45309;
    --bg: linear-gradient(135deg, #1a1a1a 0%, #2d3436 100%);
    --card: #f8f7f6;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #d4c5c1;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.25);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* =============================
   Layout
   ============================= */
.container {
    width: 100%;
    max-width: 1200px;
}

.card {
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(24px);
}

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

.data-disclaimer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    background: #d3cac0;
    border: 1px solid #f0b46a;
    padding: 10px 14px;
    font-size: 0.88em;
    color: #7a3100;
    border-radius: 10px;
    margin-bottom: 10px;
}

.data-disclaimer p {
    flex: 1;
}

.link-btn {
    background: none;
    border: none;
    color: #af4500;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-size: 0.9em;
    text-decoration: underline;
}

.link-btn:hover {
    color: #7a3100;
}

/* =============================
   Header
   ============================= */
.card-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 12px 24px 8px;
    min-height: 72px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.card-body {
    display: grid;
    grid-template-columns: minmax(0, 0.65fr) minmax(300px, 0.35fr);
    gap: 18px;
    padding: 18px;
    align-items: stretch;
}

.panel {
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    padding: 18px;
    height: 100%;
}

.calculator-panel {
    background: transparent;
    box-shadow: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
}

.card-header h1 {
    font-size: clamp(1.8rem, 2.4vw, 2.1rem);
    font-weight: 700;
    color: #fefcf5;
    letter-spacing: -0.5px;
    line-height: 1.1;
    margin-bottom: 4px;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.card-header p {
    font-size: 0.95em;
    opacity: 0.85;
    font-weight: 300;
}

.header-subtitle {
    margin-top: 4px;
    font-size: 0.95em;
    font-weight: 400;
    opacity: 0.8;
    color: rgba(255, 255, 255, 0.85);
    max-width: 520px;
}

.header-meta {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.meta-pill {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 0.75em;
    letter-spacing: 0.5px;
    padding: 6px 12px;
    border-radius: 999px;
    text-transform: uppercase;
}

/* =============================
   Buttons
   ============================= */
.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.btn {
    padding: 10px 24px;
    font-size: 0.95em;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.btn-reset {
    background: #f3f4f6;
    color: var(--text);
}

.btn-reset:hover {
    background: #e5e7eb;
    transform: translateY(-2px);
}

.btn-primary {
    background: var(--secondary);
    color: #fff;
    box-shadow: 0 10px 20px rgba(217, 119, 6, 0.25);
}

.btn-primary:hover {
    background: var(--accent);
    transform: translateY(-2px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid rgba(31, 41, 55, 0.2);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: rgba(31, 41, 55, 0.4);
}

/* =============================
   Form
   ============================= */
.calculator-form {
    padding: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
    grid-auto-flow: dense;
}

@media (min-width: 768px) {
    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1200px) {
    .form-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

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

.form-group label {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text);
    transition: var(--transition);
    letter-spacing: 0.3px;
}

.input-header label {
    font-size: 1.05em;
    font-weight: 700;
    color: #ececec;
    letter-spacing: 0.03em;
}

.form-group label:hover {
    color: var(--secondary);
}

.form-group--full {
    grid-column: 1 / -1;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dual-input-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.dual-input-field {
    flex: 1;
    min-width: 120px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dual-label {
    font-size: 0.75em;
    font-weight: 600;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.input-row .calculator-input {
    flex: 1;
}

.calculator-input {
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1em;
    transition: var(--transition);
    background: #f9fafb;
}

.calculator-input:focus {
    outline: none;
    border-color: var(--secondary);
    background: white;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

.calculator-input::placeholder {
    color: #d1d5db;
}

/* =============================
   Result Display
   ============================= */
.result {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 10px;
    background: #fef3c7;
    border-left: 3px solid var(--secondary);
    border-radius: 4px;
    font-size: 0.9em;
}

.result-label {
    color: var(--text-muted);
    font-weight: 600;
}

.result-value {
    font-size: 1.2em;
    font-weight: 700;
    color: var(--accent-light);
}

.unit {
    font-size: 0.85em;
    color: var(--text-muted);
    font-weight: 600;
}

/* =============================
   Actions
   ============================= */
.form-actions {
    display: flex;
    gap: 12px;
    padding-top: 4px;
    justify-content: flex-start;
}

/* =============================
   Quick Estimates Panel
   ============================= */
.estimates-panel {
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 15px 40px rgba(15, 23, 42, 0.12);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.estimates-panel-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.estimates-panel-header h2 {
    font-size: 1.1em;
    margin-bottom: 4px;
    color: var(--text);
}

.estimates-panel-header p {
    color: var(--text-muted);
    font-size: 0.9em;
}

.estimate-input-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

.chip-input {
    min-width: 220px;
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.95em;
    transition: var(--transition);
}

.chip-input:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
    background: #f9fafb;
}

.estimates-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: calc(100vh - 340px);
    overflow-y: auto;
}

.estimates-empty {
    text-align: center;
    padding: 32px 20px;
    border: 1px dashed rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.estimates-empty .muted {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.9em;
}

.estimate-chip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.estimate-chip__name {
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}

.estimate-chip--draft {
    background: #fffaf5;
    border-style: dashed;
}

.estimate-chip__meta {
    font-size: 0.9em;
    color: var(--accent-light);
    font-weight: 600;
}

.estimate-chip__product {
    font-size: 0.85em;
    color: var(--text-muted);
    font-style: italic;
}

.estimate-chip__time {
    font-size: 0.75em;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.3px;
}

.chip-tag {
    display: inline-block;
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--accent);
    background: rgba(146, 64, 14, 0.1);
    padding: 2px 8px;
    border-radius: 999px;
    margin-left: 6px;
}

.estimate-chip__actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chip-btn {
    border: none;
    background: #eef2ff;
    color: var(--primary);
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: var(--transition);
}

.chip-btn:hover {
    background: #ad6a1c;
}

.chip-btn.ghost {
    background: transparent;
    border: 1px dashed rgba(31, 41, 55, 0.2);
}

.chip-btn.ghost:hover {
    border-color: rgba(255, 136, 0, 0.493);
}

/* =============================
   Total Result
   ============================= */
.total-result {
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    color: white;
    padding: 18px;
    border-radius: 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    text-align: center;
    box-shadow: 0 4px 16px rgba(30, 41, 59, 0.3);
}

.result-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-label-text {
    font-size: 0.85em;
    opacity: 0.9;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.total-value {
    font-size: 2em;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.total-value .unit {
    font-size: 0.6em;
    opacity: 0.9;
    color: white;
}

.currency-symbol {
    font-size: 0.9em;
    opacity: 0.8;
}

/* =============================
   Modal
   ============================= */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    animation: slideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.3em;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.8em;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 24px;
}

.modal-body ul {
    margin: 12px 0 16px 18px;
    color: var(--text);
    line-height: 1.5;
}

.muted-note {
    color: var(--text-muted);
    font-size: 0.9em;
}

.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 16px;
}

.shortcut-item kbd {
    background: #f3f4f6;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.85em;
    font-weight: 600;
    min-width: 45px;
    text-align: center;
    color: var(--text);
}

.shortcut-item span {
    color: var(--text-muted);
}

/* =============================
   Responsive
   ============================= */
@media (min-width: 1280px) {
    .card-body {
        grid-template-columns: minmax(0, 0.6fr) minmax(320px, 0.4fr);
    }
}

@media (max-width: 1024px) {
    .card-body {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .data-disclaimer {
        flex-direction: column;
        align-items: flex-start;
    }

    .estimates-panel {
        order: 2;
    }

    .estimates-list {
        max-height: none;
    }
}

@media (max-width: 640px) {
    .card-header {
        padding: 18px 16px;
    }

    .header-top {
        flex-wrap: wrap;
    }

    .card-header h1 {
        font-size: 1.4em;
    }

    .header-meta {
        flex-direction: column;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .total-result {
        grid-template-columns: 1fr;
    }

    .estimate-input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .chip-input {
        width: 100%;
    }

    .dual-input-row {
        flex-direction: column;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --card: #1f2937;
        --text: #f3f4f6;
        --text-muted: #9ca3af;
        --border: #374151;
        --shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }

    .calculator-input {
        background: #111827;
        color: #f3f4f6;
    }

    .calculator-input:focus {
        background: #1f2937;
    }

    .result {
        background: #3d2f23;
        border-left-color: var(--secondary);
    }

    .btn-reset {
        background: #374151;
        color: #f3f4f6;
    }

    .btn-reset:hover {
        background: #4b5563;
    }

    .modal-content {
        background: #1f2937;
    }

    .modal-header {
        border-bottom-color: #374151;
        color: #f3f4f6;
    }

    .shortcut-item kbd {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .estimates-panel {
        background: #111827;
        border-color: #1f2937;
        box-shadow: none;
    }

    .chip-input {
        background: #0f172a;
        color: #f3f4f6;
        border-color: #1f2937;
    }

    .chip-input:focus {
        outline: none;
        border-color: var(--secondary);
        box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
        background: #1f2937;
    }

    .estimate-chip {
        background: #0f172a;
        border-color: #1f2937;
    }

    .chip-btn {
        background: rgba(59, 130, 246, 0.15);
        color: #bfdbfe;
    }

    .chip-btn.ghost {
        border-color: rgba(148, 163, 184, 0.5);
        color: #f3f4f6;
    }

    .btn-ghost {
        color: #f3f4f6;
        border-color: rgba(148, 163, 184, 0.4);
    }

    .dual-label {
        color: #9ca3af;
    }

    .estimate-chip--draft {
        background: #1f2230;
        border-color: #2d3142;
    }

    .chip-tag {
        color: #fb923c;
        background: rgba(251, 146, 60, 0.15);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

@media (max-width: 480px) {
    .card {
        border-radius: 15px;
    }

    .card-header {
        padding: 25px 15px;
    }

    .card-header h1 {
        font-size: 1.4em;
    }

    .card-header p {
        font-size: 0.95em;
    }

    .calculator-form {
        padding: 20px;
    }

    .result {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .total-value {
        font-size: 1.7em;
    }
}
