/* Perfect Consign Admin - mobile-first styles. Narrow layout is the default;
   `@media (min-width: 641px)` enhances for tablets and desktops. */

:root {
    --color-bg: #f5f5f5;
    --color-surface: #fff;
    --color-border: #ddd;
    --color-text: #222;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-error: #b91c1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header: stack by default, row at tablet+. */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--color-text);
}

.main-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
}

.main-nav a {
    color: var(--color-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.35rem 0.25rem;
    border-radius: 0.25rem;
}

.main-nav a:hover {
    text-decoration: underline;
}

.user-menu {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding-top: 0.65rem;
    border-top: 1px solid var(--color-border);
    gap: 0.5rem;
}

.user-menu__link {
    color: var(--color-text-muted, inherit);
    text-decoration: none;
    font-size: 0.9rem;
}

.user-menu__link:hover,
.user-menu__link:focus {
    text-decoration: underline;
}

.user-email {
    font-size: 0.9rem;
    word-break: break-word;
    max-width: 100%;
}

form.logout-form {
    display: inline;
    margin: 0;
    padding: 0;
}

form.logout-form button.logout {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    padding: 0;
    min-height: 2.75rem;
    padding: 0.35rem 0.5rem;
    display: inline-flex;
    align-items: center;
}

.logout {
    color: var(--color-primary);
    text-decoration: none;
}

.logout:hover {
    text-decoration: underline;
}

.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
}

.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: #666;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
}

.login-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
}

.login-box h1 {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.login-error {
    color: var(--color-error);
    margin-bottom: 1rem;
}

.login-notice {
    color: var(--color-success, #146c43);
    background: var(--color-success-bg, #d1e7dd);
    border: 1px solid var(--color-success-border, #a3cfbb);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}

.login-form .form-group,
.account-form .form-group {
    margin-bottom: 1rem;
}

.login-form label,
.account-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.login-form input,
.account-form input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
}

/* Password field + show/hide toggle */
.password-field {
    position: relative;
    width: 100%;
}

.login-form .password-field {
    max-width: none;
}

.store-form .password-field {
    max-width: 24rem;
}

.password-field > input {
    padding-right: 2.75rem;
}

.password-field__toggle {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem;
    margin: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #555;
    cursor: pointer;
    line-height: 0;
}

.password-field__toggle:hover {
    color: var(--color-text);
    background: rgba(0, 0, 0, 0.06);
}

.password-field__toggle:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.password-field__icon--hide {
    display: none;
}

.password-field--visible .password-field__icon--show {
    display: none;
}

.password-field--visible .password-field__icon--hide {
    display: block;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.inline-form .password-field {
    flex: 1 1 7rem;
    min-width: 6.5rem;
    max-width: 11rem;
}

/* Store users: full email visible; stack password fields so they do not overlap the Update button */
.store-user-email-form input[type="email"] {
    flex: 1 1 18rem;
    min-width: min(100%, 18rem);
    max-width: 32rem;
    width: auto;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.store-user-email-form .btn {
    flex-shrink: 0;
}

.store-user-password-form {
    flex-direction: column;
    align-items: stretch;
    max-width: 22rem;
}

.store-user-password-form .password-field {
    flex: none;
    width: 100%;
    min-width: 0;
    max-width: none;
}

.store-user-password-form > .btn {
    flex-shrink: 0;
    align-self: flex-start;
}

.store-users-page .data-table th:first-child,
.store-users-page .data-table td:first-child {
    min-width: 18rem;
}

.login-form .btn {
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    text-decoration: none;
}

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

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

.btn-secondary {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-danger {
    background: #b91c1c;
    color: #fff;
}

.btn-danger:hover {
    background: #991b1b;
}

/* Dashboard */
.dashboard h1 {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.25rem;
}

.card h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #666;
}

.metric-value {
    margin: 0;
    font-size: 1.25rem;
}

.dashboard-actions {
    margin-top: 1.5rem;
}

.account-page {
    max-width: 32rem;
}

.account-form {
    padding: 1.25rem;
}

/* Tables & pages */
.page-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-header h1 {
    margin: 0;
}

.page-header .btn {
    width: 100%;
    text-align: center;
    min-height: 2.75rem;
    box-sizing: border-box;
}

.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    background: var(--color-bg);
    font-weight: 600;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 1.5rem;
}

.data-table th.sortable:hover {
    background: #e8e8e8;
}

.data-table th.sortable::after {
    content: '\2195';
    opacity: 0.4;
    margin-left: 0.25rem;
    font-size: 0.85em;
}

.data-table th.sort-asc::after {
    content: '\2191';
    opacity: 1;
}

.data-table th.sort-desc::after {
    content: '\2193';
    opacity: 1;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: #fafafa;
}

.data-table code {
    font-size: 0.9rem;
}

.data-table td {
    vertical-align: top;
}

.data-table td .btn {
    display: inline-block;
    margin: 0.2rem 0.35rem 0.2rem 0;
    vertical-align: middle;
}

.activity-payload-pre {
    max-width: min(100%, 36rem);
    margin: 0.5rem 0 0;
    padding: 0.5rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8rem;
    background: #f5f5f5;
    border-radius: 4px;
}

.stores-list__open-storefront {
    margin-bottom: 0.75rem;
}

.form-error {
    color: var(--color-error);
    margin-bottom: 1rem;
}

.form-success {
    color: #0d9488;
    margin-bottom: 1rem;
}

.form-hint {
    font-size: 0.875rem;
    color: #666;
    margin-top: 0.25rem;
}

.required {
    color: var(--color-error);
}

.empty-state {
    margin-top: 1rem;
    color: #666;
}

/* Alerts (used for API fetch failures, tenant filter warnings, etc.) */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.alert-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

/* Store form */
.store-form .form-group {
    margin-bottom: 1rem;
}

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

.store-form input,
.store-form select {
    width: 100%;
    max-width: 24rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
}

.form-static {
    margin: 0;
    font-size: 0.9rem;
    color: #666;
}

.form-actions {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

.form-actions .btn {
    width: 100%;
    text-align: center;
    min-height: 2.75rem;
    box-sizing: border-box;
}

/* Billing page */
.billing-page .card {
    margin-bottom: 1.5rem;
}

.billing-page .card h2 {
    margin-top: 0;
}

.cancel-notice {
    color: #b45309;
}

/* Enhance for tablet+ viewports. Defaults above already cover narrow/touch;
   these rules lay out rows, shrink tap targets, and let buttons sit inline. */
@media (min-width: 641px) {
    .header-inner {
        flex-direction: row;
        align-items: center;
        gap: 1.5rem;
        flex-wrap: wrap;
    }

    .main-nav {
        flex-direction: row;
        gap: 1rem;
        width: auto;
    }

    .main-nav a {
        display: inline;
        min-height: 0;
        padding: 0;
        border-radius: 0;
    }

    .user-menu {
        margin-left: auto;
        flex-direction: row;
        align-items: center;
        width: auto;
        padding-top: 0;
        border-top: none;
        gap: 1rem;
    }

    form.logout-form button.logout {
        min-height: 0;
        padding: 0;
        display: inline;
    }

    .page-header {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .page-header .btn {
        width: auto;
        min-height: 0;
    }

    .form-actions {
        flex-direction: row;
        align-items: center;
    }

    .form-actions .btn {
        width: auto;
        min-height: 0;
    }

    .data-table td .btn {
        margin: 0;
    }
}
