/* =========================================================
 * style.css — mobile-first
 *   base (~767px)  : mobile layout
 *   >= 768px       : tablet / desktop layout
 * ========================================================= */

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ---------- App header (mobile base) ---------- */
.app-header {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 50;
}

.app-header-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
}

.app-brand {
    color: #2563eb;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hamburger button */
.nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    width: 32px;
    height: 32px;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
}

.nav-toggle:hover {
    background-color: #f0f0f0;
}

.nav-toggle-bar {
    display: block;
    width: 100%;
    height: 2px;
    background: #333;
    border-radius: 1px;
}

/* User area — on mobile, hide name/badge; logout stays compact */
.user-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.user-area .user-name,
.user-area .role-badge {
    display: none;
}

.user-name {
    color: #333;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.role-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.role-admin {
    background: #dc3545;
    color: white;
}

.role-distributor {
    background: #28a745;
    color: white;
}

.role-organization {
    background: #007bff;
    color: white;
}

.logout-form {
    display: inline;
}

.btn-logout {
    color: #666;
    background: none;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.25rem 0.55rem;
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s;
}

.btn-logout:hover {
    background-color: #f0f0f0;
}

/* ---------- Mobile menu overlay ---------- */
.mobile-menu {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 360px;
    background: #fff;
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    overflow-y: auto;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.15);
}

.mobile-menu.is-open {
    transform: translateX(0);
}

.mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 199;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.mobile-menu.is-open + .mobile-menu-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.mobile-menu-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.nav-close {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    color: #555;
}

.nav-close:hover {
    background-color: #f0f0f0;
}

.mobile-menu-title {
    font-weight: 600;
    color: #1f2937;
}

.mobile-menu-user {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
}

.mobile-menu-user-name {
    font-size: 0.95rem;
    color: #1f2937;
    font-weight: 500;
}

.mobile-menu-links {
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    flex: 1;
}

.mobile-menu-links a {
    display: block;
    padding: 0.9rem 1rem;
    color: #1f2937;
    text-decoration: none;
    border-radius: 8px;
    font-size: 1rem;
}

.mobile-menu-links a:hover,
.mobile-menu-links a:active {
    background-color: #eff6ff;
    color: #1d4ed8;
}

.mobile-menu-footer {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
}

.btn-logout-block {
    width: 100%;
    padding: 0.4rem 0.5rem;
    background: none;
    border: none;
    color: #888;
    font-family: inherit;
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
}

.btn-logout-block:hover {
    color: #555;
    background: #f3f4f6;
}

/* ---------- Main content ---------- */
.main-content {
    flex: 1;
    padding: 0.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.main-content > * {
    width: 100%;
}

/* ---------- Hero ---------- */
.hero {
    text-align: center;
    padding: 2rem 0;
}

.hero h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    color: #1f2937;
}

.welcome-message {
    font-size: 1rem;
    color: #666;
    margin-bottom: 1.5rem;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    text-align: center;
    transition: all 0.2s;
}

.btn-primary {
    background-color: #2563eb;
    color: white;
}

.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-secondary {
    background-color: #6b7280;
    color: white;
}

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

/* ---------- Dashboard ---------- */
.dashboard {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.dashboard h1 {
    font-size: 1.5rem;
    margin-bottom: 1.25rem;
    color: #1f2937;
}

.user-info,
.quick-actions {
    margin-bottom: 2rem;
}

.user-info h2,
.quick-actions h2 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    color: #374151;
}

.info-card {
    background: white;
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.info-card p {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.actions-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.action-card {
    background: white;
    padding: 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.action-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.4rem;
    color: #1f2937;
}

.action-card p {
    color: #666;
    font-size: 0.9rem;
}

.action-card.logout h3 {
    color: #dc2626;
}

/* ---------- Footer ---------- */
.footer {
    padding: 2px 0;
    text-align: center;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.footer-content {
    padding: 0 0.5rem;
}

.version-text {
    font-size: 0.65rem;
    color: #b0b6bd;
    font-family: 'Courier New', Courier, monospace;
    word-break: break-all;
}

/* ---------- Forms ---------- */
.form-section {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.form-header {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.header-row {
    font-weight: bold;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

.form-group {
    flex: 1;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.action-column {
    flex: 0 0 auto;
    text-align: left;
}

.required {
    color: #dc3545;
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Bulk input */
.bulk-input {
    width: 100%;
    font-family: monospace;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
}

.form-help {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #666;
    background-color: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border-left: 3px solid #007bff;
}

.form-help code {
    background-color: #e9ecef;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

/* =========================================================
 * Tablet / Desktop (>= 768px)
 * ========================================================= */
@media (min-width: 768px) {
    .app-header-inner {
        padding: 0.25rem 0.75rem;
        gap: 1rem;
    }

    .app-brand {
        font-size: 1rem;
    }

    /* Show name & badge in header */
    .user-area .user-name,
    .user-area .role-badge {
        display: inline-block;
    }

    .user-area .user-name {
        font-size: 0.85rem;
        text-decoration: none;
    }

    .user-area .user-name:hover {
        text-decoration: underline;
    }

    /* Main content gets a bit more breathing room */
    .main-content {
        padding: 1.5rem;
    }

    /* Hero */
    .hero {
        padding: 4rem 0;
    }

    .hero h1 {
        font-size: 3rem;
    }

    .welcome-message {
        font-size: 1.25rem;
    }

    .action-buttons {
        flex-direction: row;
        justify-content: center;
        gap: 1rem;
    }

    /* Dashboard */
    .dashboard h1 {
        font-size: 2.5rem;
        margin-bottom: 2rem;
    }

    .user-info,
    .quick-actions {
        margin-bottom: 3rem;
    }

    .user-info h2,
    .quick-actions h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .info-card {
        padding: 2rem;
    }

    .info-card p {
        font-size: 1.1rem;
    }

    .actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1rem;
    }

    .action-card {
        padding: 2rem;
    }

    .action-card h3 {
        font-size: 1.25rem;
    }

    .action-card p {
        font-size: 1rem;
    }

    /* Forms */
    .form-section {
        padding: 1.5rem;
    }

    .form-row {
        flex-direction: row;
        gap: 1rem;
        align-items: center;
    }

    .action-column {
        flex: 0 0 80px;
        text-align: center;
    }

    .form-actions {
        flex-direction: row;
        gap: 1rem;
    }

    .version-text {
        font-size: 0.7rem;
    }
}
