:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-bg: #f3f4f6;
    --color-card: #ffffff;
    --color-text: #1f2937;
    --color-muted: #6b7280;
    --color-success: #16a34a;
    --color-danger: #dc2626;
    --radius: 12px;
    --app-max-width: 480px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
}

.app {
    max-width: var(--app-max-width);
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

header.topbar {
    background: var(--color-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

header.topbar h1 {
    font-size: 18px;
    margin: 0;
    font-weight: 600;
}

header.topbar .logout-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

main {
    flex: 1;
    padding: 16px;
    padding-bottom: 100px;
}

.card {
    background: var(--color-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.balance-card {
    text-align: center;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff;
}

.balance-card .label {
    font-size: 14px;
    opacity: 0.85;
}

.balance-card .amount {
    font-size: 40px;
    font-weight: 700;
    margin: 8px 0 0;
}

.balance-card .amount span {
    font-size: 18px;
    font-weight: 400;
    opacity: 0.8;
}

h2 {
    font-size: 16px;
    margin: 0 0 12px;
}

form .field {
    margin-bottom: 14px;
}

label {
    display: block;
    font-size: 13px;
    color: var(--color-muted);
    margin-bottom: 6px;
}

input, textarea, select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    background: #fff;
    color: var(--color-text);
}

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

button.btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 8px;
    background: var(--color-primary);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

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

button.btn:disabled {
    opacity: 0.6;
}

a.link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 14px;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 14px;
}

.alert-error {
    background: #fee2e2;
    color: var(--color-danger);
}

.alert-success {
    background: #dcfce7;
    color: var(--color-success);
}

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

.muted {
    color: var(--color-muted);
    font-size: 13px;
}

/* Transaction list */
.tx-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.tx-item:last-child {
    border-bottom: none;
}

.tx-info .tx-title {
    font-size: 14px;
    font-weight: 500;
}

.tx-info .tx-date {
    font-size: 12px;
    color: var(--color-muted);
}

.tx-amount {
    font-weight: 700;
    font-size: 15px;
}

.tx-amount.incoming {
    color: var(--color-success);
}

.tx-amount.outgoing {
    color: var(--color-danger);
}

/* Bottom navigation for mobile */
nav.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: var(--app-max-width);
    margin: 0 auto;
    background: #fff;
    display: flex;
    border-top: 1px solid #e5e7eb;
}

nav.bottom-nav a {
    flex: 1;
    text-align: center;
    padding: 14px 2px;
    font-size: 12px;
    line-height: 1.3;
    color: var(--color-muted);
    text-decoration: none;
    white-space: nowrap;
}

nav.bottom-nav a.active {
    color: var(--color-primary);
    font-weight: 600;
}

nav.bottom-nav .icon {
    display: block;
    font-size: 22px;
    margin-bottom: 4px;
}

/* Generic modal dialog (used for add-product form, QR scanner, etc.) */
.form-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.form-modal-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
}

.form-modal-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    max-width: 420px;
    width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    z-index: 1001;
}

.form-modal-content h2 {
    margin-top: 0;
}

.form-modal-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #fff;
    font-size: 18px;
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* QR code (student dashboard) and QR scanner (teacher/director) */
.qr-code-box {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}

.qr-code-box img,
.qr-code-box canvas {
    border-radius: 8px;
}

#qr-video {
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
}

button.qr-scan-btn {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    padding: 10px 0;
    font-size: 16px;
}

/* Auth pages */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--color-muted);
    margin-bottom: 20px;
    font-size: 14px;
}

.auth-footer {
    text-align: center;
    margin-top: 14px;
    font-size: 14px;
}

.suggestions {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    margin-top: 6px;
    overflow: hidden;
    background: #fff;
}

.suggestions .suggestion-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
}

.suggestions .suggestion-item:hover,
.suggestions .suggestion-item.active {
    background: #f3f4f6;
}

/* ============================================================
   Адаптація для планшетів/ноутбуків: розширюємо контейнер і
   розкладаємо картки у сітку з кількох колонок.
   ============================================================ */
@media (min-width: 700px) {
    :root {
        --app-max-width: 1000px;
    }

    body {
        background: #e5e7eb;
    }

    .app {
        box-shadow: 0 0 32px rgba(0, 0, 0, 0.06);
    }

    main {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
        gap: 16px;
        align-content: start;
        padding-bottom: 16px;
    }

    .card {
        margin-bottom: 0;
        overflow-x: auto;
    }

    /* Картки з таблицями, списками операцій, графіками та балансом
       займають усю ширину сітки, щоб не стискатись у вузьку колонку */
    .balance-card,
    .card:has(table),
    .card:has(.tx-list),
    .card:has(#daily-chart),
    .card:has(form) {
        grid-column: 1 / -1;
    }

    nav.bottom-nav {
        position: static;
        margin: 16px auto 0;
        border-radius: var(--radius);
        border-top: none;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
        grid-column: 1 / -1;
    }
}

@media (min-width: 1200px) {
    :root {
        --app-max-width: 1200px;
    }

    main {
        grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    }
}
