:root {
    --bg: #eef5ef;
    --ink: #14201a;
    --muted: #657067;
    --panel: rgba(255, 255, 255, 0.88);
    --panel-solid: #ffffff;
    --green: #13794b;
    --green-dark: #0d5a39;
    --lime: #c6e86a;
    --gold: #f2b84b;
    --coral: #dc634f;
    --line: rgba(20, 32, 26, 0.12);
    --shadow: 0 22px 60px rgba(20, 32, 26, 0.18);
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    background:
        radial-gradient(circle at 8% 10%, rgba(198, 232, 106, 0.48), transparent 28%),
        radial-gradient(circle at 92% 8%, rgba(242, 184, 75, 0.38), transparent 24%),
        linear-gradient(135deg, #eef5ef 0%, #f8fbf6 48%, #e8f0ec 100%);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.app-shell {
    width: min(1440px, calc(100% - 28px));
    margin: 0 auto;
    padding: 22px 0 42px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.login-card {
    width: min(460px, 100%);
    padding: 28px;
    border: 1px solid rgba(255, 255, 255, 0.74);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.login-brand h1 {
    margin: 8px 0 8px;
    color: var(--green-dark);
    font-size: clamp(1.8rem, 7vw, 3rem);
    line-height: 1;
}

.login-brand p, .login-help, .setup-note {
    margin: 0;
    color: var(--muted);
    line-height: 1.55;
}

.login-form {
    display: grid;
    gap: 14px;
    margin-top: 22px;
}

.setup-note {
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

.hero-panel, .panel, .print-invoice {
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

.hero-panel {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 160px;
    padding: clamp(22px, 5vw, 42px);
    border-radius: var(--radius);
    color: #ffffff;
    background:
        linear-gradient(130deg, rgba(13, 90, 57, 0.97), rgba(19, 121, 75, 0.92)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='120' viewBox='0 0 240 120'%3E%3Cg fill='none' stroke='rgba(255,255,255,.18)' stroke-width='2'%3E%3Cpath d='M12 96c34-42 72-42 114 0s77 38 102 0'/%3E%3Cpath d='M22 26c28 20 56 20 84 0s58-20 90 0'/%3E%3C/g%3E%3C/svg%3E");
    transform: perspective(1000px) rotateX(0.6deg);
}

.hero-panel::after {
    content: "";
    position: absolute;
    inset: auto 34px -42px auto;
    width: 230px;
    height: 140px;
    border-radius: 40%;
    background: rgba(198, 232, 106, 0.25);
    transform: rotate(-14deg);
}

.hero-panel h1 {
    position: relative;
    z-index: 1;
    max-width: 820px;
    margin: 8px 0 10px;
    font-size: clamp(2rem, 5vw, 4.15rem);
    line-height: 1;
    letter-spacing: 0;
}

.hero-panel p {
    position: relative;
    z-index: 1;
    max-width: 620px;
    margin: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 1.02rem;
}

.hero-actions {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ghost-link {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-radius: var(--radius);
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
    font-weight: 800;
}

.eyebrow, .section-kicker {
    display: block;
    margin: 0;
    color: var(--green);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hero-panel .eyebrow { color: var(--lime); }

.workspace-grid, .preview-grid {
    display: grid;
    grid-template-columns: 1.35fr 0.85fr;
    gap: 18px;
    margin-top: 18px;
    align-items: start;
}

.preview-grid.text-only { grid-template-columns: 1fr; }

.panel, .print-invoice {
    border-radius: var(--radius);
    background: var(--panel);
}

.panel { padding: 20px; }

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-heading h2 { margin: 4px 0 0; font-size: 1.25rem; }

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

input, select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.94);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus, select:focus {
    border-color: rgba(19, 121, 75, 0.65);
    box-shadow: 0 0 0 4px rgba(19, 121, 75, 0.12);
    transform: translateY(-1px);
}

.product-form, .bill-form { display: grid; gap: 14px; }

.customer-grid, .line-inputs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.line-editor {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.58);
}

.line-inputs { grid-template-columns: minmax(180px, 1.2fr) repeat(2, minmax(120px, 0.7fr)); }

.primary-btn, .secondary-btn, .ghost-btn, .whatsapp-btn, .danger-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    border: 0;
    border-radius: var(--radius);
    padding: 0 16px;
    font-weight: 800;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary-btn { color: #ffffff; background: linear-gradient(135deg, var(--green), var(--green-dark)); box-shadow: 0 14px 26px rgba(19, 121, 75, 0.26); }
.secondary-btn { color: #16241c; background: linear-gradient(135deg, var(--lime), #e8f9b0); }
.whatsapp-btn { color: #ffffff; background: linear-gradient(135deg, #1fa855, #0c7a43); }
.ghost-btn { color: var(--green-dark); background: rgba(19, 121, 75, 0.1); }
.danger-btn { min-height: 36px; color: #ffffff; background: var(--coral); }

.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .whatsapp-btn:hover, .danger-btn:hover, .ghost-link:hover {
    transform: translateY(-2px);
    filter: brightness(1.02);
}

button:disabled { cursor: not-allowed; opacity: 0.5; transform: none; }
.full { width: 100%; }

.product-list, .invoice-items { display: grid; gap: 10px; }
.product-list, .invoice-items { display: grid; gap: 10px; }
.product-tabs {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.product-tab {
    flex: 0 0 auto;
    min-height: 38px;
    border: 1px solid rgba(19, 121, 75, 0.18);
    border-radius: var(--radius);
    padding: 0 11px;
    color: var(--green-dark);
    background: rgba(255, 255, 255, 0.72);
    font-size: 0.82rem;
    font-weight: 800;
}
.product-tab span {
    display: inline-flex;
    min-width: 22px;
    min-height: 22px;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    border-radius: 999px;
    color: #ffffff;
    background: rgba(19, 121, 75, 0.7);
    font-size: 0.72rem;
}
.product-tab.active {
    color: #ffffff;
    background: linear-gradient(135deg, var(--green), var(--green-dark));
    box-shadow: 0 10px 20px rgba(19, 121, 75, 0.18);
}
.product-tab.active span { color: var(--green-dark); background: var(--lime); }
.product-list { margin-top: 14px; max-height: 520px; overflow: auto; padding-right: 4px; }

.product-card, .invoice-line {
    display: grid;
    gap: 10px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.84);
    animation: riseIn 0.28s ease both;
}

.product-card { grid-template-columns: 1fr auto; align-items: center; }
.product-card h3, .invoice-line h3 { margin: 0; font-size: 0.98rem; }
.product-card p, .invoice-line p { margin: 4px 0 0; color: var(--muted); font-size: 0.86rem; }
.card-actions, .line-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-actions button, .line-actions button { min-height: 34px; padding: 0 11px; }

.invoice-chip {
    min-width: 150px;
    border-radius: 999px;
    padding: 8px 11px;
    color: var(--green-dark);
    background: rgba(198, 232, 106, 0.36);
    font-size: 0.8rem;
    font-weight: 800;
    text-align: center;
}

.invoice-line { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.line-amount { font-size: 1.05rem; font-weight: 900; color: var(--green-dark); white-space: nowrap; }
.discount-box { display: grid; justify-content: end; }
.discount-box label { width: min(280px, 100%); }

.totals-box {
    margin-left: auto;
    width: min(420px, 100%);
    display: grid;
    gap: 8px;
    padding: 16px;
    border-radius: var(--radius);
    background: #15241c;
    color: #ffffff;
}

.totals-box div { display: flex; justify-content: space-between; gap: 16px; }
.totals-box span { color: rgba(255, 255, 255, 0.72); }
.totals-box .grand { margin-top: 6px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.18); font-size: 1.16rem; }
.action-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.text-preview-panel pre {
    min-height: 270px;
    max-height: 460px;
    overflow: auto;
    margin: 0;
    padding: 16px;
    border-radius: var(--radius);
    color: #112016;
    background: #f7fbf5;
    border: 1px solid var(--line);
    white-space: pre-wrap;
    line-height: 1.65;
}

.print-source {
    position: fixed;
    left: -120vw;
    top: 0;
    width: 900px;
    pointer-events: none;
    opacity: 0;
}

.print-invoice { padding: 26px; background: var(--panel-solid); }
.print-invoice header { display: grid; gap: 4px; padding-bottom: 18px; border-bottom: 2px solid var(--green); }
.print-invoice h2 { margin: 0; color: var(--green-dark); font-size: clamp(1.55rem, 3vw, 2.4rem); }
.print-invoice p { margin: 0; color: var(--muted); }
.print-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 18px 0; }
.print-meta div, .print-totals { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.print-meta span { display: block; color: var(--muted); font-size: 0.74rem; font-weight: 800; text-transform: uppercase; }
.print-meta strong { display: block; margin-top: 4px; word-break: break-word; }

table { width: 100%; border-collapse: collapse; overflow: hidden; border-radius: var(--radius); }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; font-size: 0.9rem; }
th { color: #ffffff; background: var(--green-dark); }
td { background: #ffffff; }
.print-totals { display: grid; gap: 8px; width: min(360px, 100%); margin: 18px 0 0 auto; }
.print-totals div { display: flex; justify-content: space-between; gap: 16px; }
.print-totals .grand { padding-top: 8px; border-top: 1px solid var(--line); color: var(--green-dark); font-size: 1.15rem; font-weight: 900; }
.print-invoice footer { display: grid; gap: 4px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); text-align: center; color: var(--green-dark); }

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
    max-width: min(360px, calc(100% - 36px));
    padding: 12px 14px;
    border-radius: var(--radius);
    color: #ffffff;
    background: #15241c;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translateY(18px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.app-animate { animation: floatIn 0.46s cubic-bezier(.2,.8,.2,1) both; }
.delay-1 { animation-delay: 0.06s; }
.delay-2 { animation-delay: 0.12s; }
.delay-3 { animation-delay: 0.18s; }

@keyframes riseIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes floatIn { from { opacity: 0; transform: translateY(18px) scale(0.985); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (max-width: 1050px) {
    .workspace-grid, .preview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .app-shell { width: min(100% - 18px, 1440px); padding-top: 9px; }
    .hero-panel, .panel, .login-card { box-shadow: 0 12px 30px rgba(20, 32, 26, 0.12); }
    .hero-panel, .panel-heading, .action-row, .hero-actions { align-items: stretch; flex-direction: column; }
    .hero-panel { min-height: auto; padding: 20px; }
    .hero-panel h1 { font-size: 2rem; }
    .customer-grid, .line-inputs, .print-meta { grid-template-columns: 1fr; }
    .product-card, .invoice-line { grid-template-columns: 1fr; }
    .line-amount { white-space: normal; }
    .discount-box { justify-content: stretch; }
    .action-row button, .hero-panel button, .ghost-link { width: 100%; }
    .text-preview-panel pre { min-height: 220px; }
    th, td { padding: 9px 7px; font-size: 0.78rem; }
    .toast { right: 9px; bottom: 9px; max-width: calc(100% - 18px); }
}

@media print {
    body { background: #ffffff; }
    .hero-panel, .workspace-grid, .preview-grid, .toast { display: none !important; }
    .app-shell { width: 100%; padding: 0; }
    .print-source {
        position: static !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }
    .print-invoice { border: 0; box-shadow: none; padding: 0; }
}
