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

/* ── Base ─────────────────────────────────────────────────────────────────── */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    padding: 24px 16px calc(80px + env(safe-area-inset-bottom));
}

h1 {
    font-size: 1.5rem;
}

.page-title {
    font-size: 1.4rem;
    margin-bottom: 20px;
    color: #1a1a2e;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

@media (min-width: 1024px) {
    .container {
        max-width: 1400px;
    }
}

/* ── Page header (back link + title row) ──────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.page-header a {
    color: #4a6cf7;
    text-decoration: none;
    font-size: 0.9rem;
}

.page-header h1 {
    flex: 1;
}

.btn-add {
    padding: 8px 16px;
    background: #4a6cf7;
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s;
}

.btn-add:hover {
    background: #3a5ce5;
}

/* ── Form elements ────────────────────────────────────────────────────────── */
input[type="text"],
select {
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: #1a1a2e;
}

input[type="text"]:focus,
select:focus {
    border-color: #4a6cf7;
}

/* ── index.php: centered home layout ─────────────────────────────────────── */
body.page-home {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

body.page-home h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 3rem;
}

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
    max-width: 480px;
}

.btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    text-decoration: none;
    color: #1a1a2e;
    font-size: 1.1rem;
    font-weight: 600;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    background: #f7f9ff;
    border-color: #4a6cf7;
}

.btn:active {
    transform: scale(0.97);
}

.btn svg {
    width: 36px;
    height: 36px;
    stroke: #4a6cf7;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── search.php ───────────────────────────────────────────────────────────── */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
}

.search-bar input[type="text"] {
    flex: 1;
    padding: 12px 16px;
}

#status {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 12px;
    min-height: 1.2em;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

thead {
    background: #1a1a2e;
    color: #fff;
}

thead th {
    padding: 12px 14px;
    text-align: center;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

tbody tr:nth-child(even) {
    background: #f9fafc;
}

tbody tr:hover {
    background: #eef1ff;
}

td {
    padding: 10px 14px;
    font-size: 0.9rem;
    vertical-align: middle;
    text-align: center;
    border-top: 1px solid #f0f0f0;
}

td:first-child,
td:nth-child(2),
td.col-recipients,
td.col-notes {
    text-align: left;
}

.col-added-date {
    white-space: nowrap;
}

.alias-cell {
    font-family: monospace;
    color: #4a6cf7;
    white-space: nowrap;
}

.alias-modal-trigger {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    -webkit-tap-highlight-color: transparent;
}

.empty-state {
    text-align: center;
    color: #888;
    padding: 40px;
    font-size: 0.95rem;
}

/* ── add.php ──────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.alias-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: #888;
    margin-top: 6px;
    font-family: monospace;
}

.error {
    background: #fff1f0;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.success-box {
    background: #fff;
    border: 2px solid #22c55e;
    border-radius: 12px;
    padding: 32px;
    text-align: center;
}

.success-box h2 {
    color: #16a34a;
    margin-bottom: 12px;
}

.new-address {
    font-family: monospace;
    font-size: 1.4rem;
    color: #1a1a2e;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 14px 20px;
    margin: 16px 0 24px;
    word-break: break-all;
}

.success-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.success-box a {
    display: inline-block;
    padding: 12px 24px;
    background: #4a6cf7;
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
}

.btn-show-modal {
    display: inline-block;
    padding: 12px 24px;
    background: none;
    color: #4a6cf7;
    border: 2px solid #4a6cf7;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-show-modal:hover {
    background: #4a6cf7;
    color: #fff;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: #000;
    align-items: center;
    justify-content: center;
    z-index: 200;
    -webkit-tap-highlight-color: transparent;
}

.modal-overlay.active {
    display: flex;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}

.modal-address {
    font-family: monospace;
    font-size: clamp(1.6rem, 6vw, 3rem);
    color: #fff;
    text-align: center;
    padding: 24px;
    word-break: break-all;
    pointer-events: none;
}

.btn-submit {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 700;
    background: #4a6cf7;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn-submit:hover {
    background: #3a5ce5;
}

.btn-submit:active {
    transform: scale(0.98);
}

/* ── Login page ──────────────────────────────────────────────────────────── */
body.page-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 32px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    text-align: center;
    width: 100%;
    max-width: 360px;
}

.login-card h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.login-card .subtitle {
    margin-bottom: 2rem;
}

.login-card .error {
    margin-bottom: 1.5rem;
    text-align: left;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 12px 20px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: #1a1a2e;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-google:hover {
    border-color: #4a6cf7;
    box-shadow: 0 1px 6px rgba(74,108,247,0.15);
}

.btn-google svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 0;
    min-height: 56px;
    text-decoration: none;
    color: #aaa;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-item.active,
.nav-item:hover {
    color: #4a6cf7;
}

/* ── Table edit link ─────────────────────────────────────────────────────── */
.edit-link {
    color: #4a6cf7;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.edit-link:hover {
    text-decoration: underline;
}

/* ── edit.php: delete button ─────────────────────────────────────────────── */
.btn-delete {
    width: 100%;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    background: none;
    color: #b91c1c;
    border: 2px solid #fca5a5;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.15s, border-color 0.15s;
}

.btn-delete:hover {
    background: #fff1f0;
    border-color: #b91c1c;
}

/* ── Refresh alias button ────────────────────────────────────────────────── */
.btn-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #4a6cf7;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.btn-refresh svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.4s ease;
}

.btn-refresh.spinning svg {
    animation: spin 0.5s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── add.php: alias type toggle ──────────────────────────────────────────── */
.alias-type {
    display: flex;
    gap: 24px;
}

.alias-type-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    color: #1a1a2e;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
}

.alias-type-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: #4a6cf7;
    cursor: pointer;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .col-recipients,
    .col-flag,
    .col-added-by,
    .col-added-date,
    .col-notes {
        display: none;
    }

    td, th {
        padding: 10px;
    }

    /* Larger touch target for edit link on mobile */
    .edit-link {
        display: inline-block;
        padding: 6px 4px;
    }
}

@media (max-width: 480px) {
    body {
        padding-left: 12px;
        padding-right: 12px;
    }

    .card {
        padding: 20px 16px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    /* Ensure inputs/selects have adequate touch targets */
    input[type="text"],
    select {
        font-size: 1rem; /* prevents iOS zoom on focus */
        min-height: 44px;
    }

    .alias-type-option {
        min-height: 44px;
    }

    .btn-submit,
    .btn-delete {
        min-height: 48px;
    }
}
