/* ===== CSS Variables ===== */
:root {
    --primary: #16a34a;
    --primary-hover: #15803d;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --blue: #2563eb;
    --purple: #9333ea;
    --text: #1f2937;
    --text-muted: #6b7280;
    --bg: #f9fafb;
    --white: #ffffff;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 0.5rem;
}

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

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

/* ===== Typography ===== */
h1,
h2,
h3 {
    font-weight: 700;
}

h1 {
    font-size: 1.875rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.125rem;
}

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

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

.text-green {
    color: var(--primary);
}

.text-red {
    color: var(--danger);
}

.text-blue {
    color: var(--blue);
}

.text-lg {
    font-size: 1.125rem;
    font-weight: 600;
}

.text-xl {
    font-size: 1.5rem;
    font-weight: 700;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

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

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: rgba(22, 163, 74, 0.1);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(220, 38, 38, 0.1);
}

.btn-icon {
    padding: 0.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* ===== Cards ===== */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

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

.card-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body {
    padding: 1rem;
}

.card-link {
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s;
}

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

.card-profit {
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border-color: #a7f3d0;
}

.card-empty {
    border-style: dashed;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.input-with-button {
    display: flex;
    gap: 0.5rem;
}

.input-with-button input {
    flex: 1;
}

/* ===== Grid ===== */
.grid {
    display: grid;
    gap: 1rem;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* ===== Layout ===== */
.page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
    padding-bottom: 7rem;
}

/* Adjust layout for desktop to accommodate fixed desktop-nav */
@media (min-width: 1024px) {
    .page-container {
        margin-left: 120px;
        margin-right: auto;
        max-width: calc(100% - 140px);
    }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== Header ===== */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 2.5rem;
    height: 2.5rem;
    background: var(--primary);
    color: var(--white);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
}

.logo-icon.large {
    width: 4rem;
    height: 4rem;
    font-size: 2rem;
}

.logo h1 {
    font-size: 1.25rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-email {
    font-size: 0.875rem;
    color: var(--text-muted);
}

@media (max-width: 640px) {
    .user-email {
        display: none;
    }
}

/* ===== Navigation ===== */
.desktop-nav {
    display: none !important;
    position: fixed;
    left: 1rem;
    top: 6rem;
    flex-direction: column;
    gap: 0.5rem;
}

@media (min-width: 1024px) {
    .desktop-nav {
        display: flex !important;
    }

    .mobile-nav {
        display: none !important;
    }
}

.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: var(--white);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.625rem;
    transition: all 0.2s;
    min-width: 0;
    overflow: hidden;
}

.nav-link span:not(.nav-icon) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary);
    background: rgba(22, 163, 74, 0.05);
}

.nav-icon {
    font-size: 1.25rem;
    margin-bottom: 0.125rem;
}

/* Very small screens - show only icons */
@media (max-width: 360px) {
    .nav-link span:not(.nav-icon) {
        display: none;
    }

    .nav-icon {
        margin-bottom: 0;
    }

    .nav-link {
        padding: 0.75rem 0.5rem;
    }
}

/* ===== Flash Messages ===== */
.flash-messages {
    position: fixed;
    top: 4.5rem;
    right: 1rem;
    z-index: 1000;
    max-width: 400px;
}

.flash {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

.flash-success {
    background: #dcfce7;
    color: #166534;
}

.flash-error {
    background: #fee2e2;
    color: #991b1b;
}

.flash-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.7;
}

.flash-close:hover {
    opacity: 1;
}

/* ===== Landing Page ===== */
.landing-page {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.landing-container {
    max-width: 48rem;
    padding: 2rem;
}

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

.landing-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.landing-icon {
    font-size: 3rem;
}

.landing-title {
    font-size: 2rem;
    color: #166534;
}

@media (min-width: 768px) {
    .landing-title {
        font-size: 3rem;
    }
}

.landing-description {
    font-size: 1.125rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.landing-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (min-width: 640px) {
    .landing-buttons {
        flex-direction: row;
        justify-content: center;
    }
}

.landing-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 2rem;
}

@media (max-width: 640px) {
    .landing-stats {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background: var(--white);
    padding: 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.stat-title {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.stat-icon {
    font-size: 1.25rem;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.875rem;
    font-weight: 700;
}

.stat-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ===== Auth Pages ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
}

.auth-card {
    background: var(--white);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h2 {
    margin-top: 1rem;
}

.auth-header p {
    color: var(--text-muted);
}

.auth-form {
    margin-bottom: 1.5rem;
}

.auth-footer {
    text-align: center;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* ===== Dashboard ===== */
.profit-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #166534;
    margin-bottom: 0.5rem;
}

.profit-value {
    font-size: 3rem;
    font-weight: 700;
    color: #166534;
    margin-bottom: 0.5rem;
}

.profit-margin {
    font-size: 0.875rem;
    color: #166534;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.quick-action-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.bg-purple {
    background: #f3e8ff;
}

.bg-green {
    background: #dcfce7;
}

.quick-action h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.quick-action p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    color: #d1d5db;
    margin-bottom: 1rem;
}

/* ===== Recipes ===== */
.recipe-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
}

.recipe-name {
    margin-bottom: 0.25rem;
}

.recipe-actions {
    display: flex;
    gap: 0.25rem;
}

.badge {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    background: #f3f4f6;
    border-radius: 9999px;
    color: var(--text-muted);
}

.badge-green {
    background: #dcfce7;
    color: #166534;
}

.recipe-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.recipe-stat {
    display: flex;
    flex-direction: column;
}

.recipe-stat .label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.recipe-stat .value {
    font-size: 1rem;
    font-weight: 600;
}

.recipe-profit {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}

.ingredient-row {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.ingredient-row:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* ===== Sales ===== */
.tally-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tally-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: var(--radius);
}

.tally-info {
    display: flex;
    flex-direction: column;
}

.tally-name {
    font-weight: 500;
}

.tally-price {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.tally-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tally-input {
    width: 4rem;
    text-align: center;
    font-size: 1.125rem;
    font-weight: 700;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.card-summary {
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border-color: #a7f3d0;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.summary-profit {
    border-top: 1px solid #a7f3d0;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
}

.sales-history {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-item {
    padding: 1rem;
    background: #f9fafb;
    border-radius: var(--radius);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.history-date {
    font-weight: 500;
}

.history-notes {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.history-stats {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.875rem;
}

.history-stat {
    display: flex;
    justify-content: space-between;
}

.history-profit {
    border-top: 1px solid var(--border);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    font-weight: 500;
}

/* ===== Main Content ===== */
.main-content.with-nav {
    padding-top: 1rem;
}

/* ===== Google Login ===== */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-divider span {
    padding: 0 1rem;
}

.btn-google {
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.btn-google:hover {
    background: #f8f9fa;
    border-color: #dadce0;
}

.google-icon {
    flex-shrink: 0;
}

/* ===== Tally Buttons (Sales Page) ===== */
.btn-tally {
    width: 3.5rem;
    height: 3.5rem;
    min-width: 3.5rem;
    font-size: 1.75rem;
    font-weight: 700;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-tally:active {
    transform: scale(0.95);
}

.btn-minus {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-minus:hover {
    background: rgba(220, 38, 38, 0.1);
}

.btn-plus {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-plus:hover {
    background: rgba(22, 163, 74, 0.1);
}

.tally-input {
    width: 4rem;
    height: 3.5rem;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 0.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

@media (max-width: 480px) {
    .btn-tally {
        width: 3rem;
        height: 3rem;
        min-width: 3rem;
        font-size: 1.5rem;
    }

    .tally-input {
        width: 3.5rem;
        height: 3rem;
        font-size: 1.25rem;
    }

    .tally-item {
        padding: 0.5rem;
    }

    .tally-name {
        font-size: 0.9375rem;
    }
}