/* ==========================================================================
   Card Wallet LKR
   ========================================================================== */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg-main: #f3f4f6;
    --surface: #ffffff;
    --surface-muted: #f9fafb;
    --text-dark: #111827;
    --text-muted: #6b7280;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --border: #e5e7eb;

    --radius: 14px;
    --radius-sm: 8px;
    --pad: 20px;
    --slide-time: 0.35s;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

/* No tap flash, no accidental text selection */
* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Typing fields must stay selectable or iOS won't let you type */
input,
textarea,
select {
    -webkit-user-select: text;
    user-select: text;
}

/* Hide the focus ring after mouse/touch clicks (keyboard users still get it) */
:focus:not(:focus-visible) {
    outline: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.4;
    background-color: var(--bg-main);
    color: var(--text-dark);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

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

/* ---------- App shell ---------- */

.app-container {
    position: relative;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: 100dvh;
    background-color: var(--surface);
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

@media (min-width: 600px) {
    .app-container {
        max-width: 720px;
        height: 92vh;
        height: min(92dvh, 900px);
        border-radius: 20px;
    }
}

/* ---------- Screens (slide transition) ---------- */

.view-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--surface);
    transition: transform var(--slide-time) ease-in-out,
                visibility 0s linear var(--slide-time);
}

.main-view {
    z-index: 1;
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--slide-time) ease-in-out, visibility 0s; /* show immediately when returning */
}

.details-view {
    z-index: 2;
    transform: translateX(100%);
    visibility: hidden; /* keeps off-screen controls out of tab order */
}

.app-container.slide-active .main-view {
    transform: translateX(-30%);
    visibility: hidden;
}

.app-container.slide-active .details-view {
    transform: translateX(0);
    visibility: visible;
}

.app-container.slide-active .view-screen {
    transition: transform var(--slide-time) ease-in-out, visibility 0s;
}

.app-container.slide-active .main-view {
    transition: transform var(--slide-time) ease-in-out, visibility 0s linear var(--slide-time);
}

/* Header stays put, content below it scrolls */
.app-header,
.details-header {
    flex: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: calc(var(--pad) + var(--safe-top)) var(--pad) 14px;
    border-bottom: 1px solid var(--border);
    background-color: var(--surface);
}

.scroll-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--pad);
    padding-bottom: calc(var(--pad) + var(--safe-bottom));
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.file-actions,
.header-right-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---------- Icon buttons ---------- */

.icon-btn,
.btn-icon,
.btn-icon-sm,
.btn-danger-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.icon-btn,
.btn-icon {
    width: 38px;
    height: 38px;
    background: var(--bg-main);
    font-size: 1rem;
}

.icon-btn:hover,
.btn-icon:hover {
    background: var(--border);
}

.btn-icon-sm {
    width: 30px;
    height: 30px;
    background: var(--border);
    font-size: 0.8rem;
}

.btn-icon-sm:hover {
    background: #d1d5db;
}

.btn-danger-icon {
    width: 36px;
    height: 36px;
    background: #fee2e2;
    color: var(--danger);
}

.btn-danger-icon:hover {
    background: #fecaca;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--primary);
}

/* ---------- Card list ---------- */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    align-content: start;
    gap: 16px;
    /* extra room so the FAB never covers the last card */
    padding-bottom: calc(100px + var(--safe-bottom));
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}

/* Swipe-left wrapper: the hint sits behind the card and is revealed as it slides */
.card-swipe {
    position: relative;
}

.swipe-hint {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary);
    opacity: 0;
    pointer-events: none;
}

.swipe-hint i {
    font-size: 1.2rem;
}

.swipe-note {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.credit-card-ui {
    --status: var(--success);
    position: relative;
    padding: 20px;
    border-radius: var(--radius);
    color: var(--card-fg);
    background: var(--card-bg);
    /* status stripe drawn inside the rounded corners instead of a border */
    box-shadow: inset 6px 0 0 var(--status), 0 8px 16px rgba(0, 0, 0, 0.12);
    touch-action: pan-y;      /* vertical scroll stays native, horizontal drag is ours */
    user-select: none;
    -webkit-user-select: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

.credit-card-ui.dragging {
    transition: none;
}

.credit-card-ui:hover {
    transform: translateY(-3px);
    box-shadow: inset 6px 0 0 var(--status), 0 12px 20px rgba(0, 0, 0, 0.18);
}

/* ---------- Card color palette ---------- */

.color-red       { --card-bg: linear-gradient(135deg, #ef4444, #b91c1c); --card-fg: #fff; }
.color-orange    { --card-bg: linear-gradient(135deg, #fb923c, #ea580c); --card-fg: #fff; }
.color-blue      { --card-bg: linear-gradient(135deg, #3b82f6, #1d4ed8); --card-fg: #fff; }
.color-lightblue { --card-bg: linear-gradient(135deg, #bae6fd, #38bdf8); --card-fg: #0c4a6e; --badge-bg: rgba(0, 0, 0, 0.1); }
.color-purple    { --card-bg: linear-gradient(135deg, #8b5cf6, #6d28d9); --card-fg: #fff; }
.color-darkgreen { --card-bg: linear-gradient(135deg, #15803d, #14532d); --card-fg: #fff; }
.color-yellow    { --card-bg: linear-gradient(135deg, #fde047, #facc15); --card-fg: #422006; --badge-bg: rgba(0, 0, 0, 0.1); }
.color-black     { --card-bg: linear-gradient(135deg, #374151, #050505); --card-fg: #fff; }
.color-pink      { --card-bg: linear-gradient(135deg, #f9a8d4, #db2777); --card-fg: #fff; }
.color-white     { --card-bg: linear-gradient(135deg, #ffffff, #e5e7eb); --card-fg: #111827; --badge-bg: rgba(0, 0, 0, 0.08); }

.credit-card-ui.color-white {
    border: 1px solid #d1d5db;
}

.credit-card-ui.status-declined    { --status: var(--danger); }
.credit-card-ui.status-low_balance { --status: var(--warning); }
.credit-card-ui.status-working     { --status: var(--success); }

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.card-bank {
    min-width: 0;
    min-height: 30px;
    display: flex;
    align-items: center;
    font-size: 1rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-chip {
    width: 36px;
    height: 26px;
    background: linear-gradient(135deg, #fef08a, #ca8a04);
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.card-brand-logo {
    flex: none;
    height: 30px;
    display: flex;
    align-items: center;
}

.card-brand-logo svg {
    height: 100%;
    width: auto;
    max-width: 60px;
}

.card-number-display {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: clamp(0.95rem, 4.6vw, 1.2rem);
    letter-spacing: 1.5px;
    margin-bottom: 16px;
    white-space: nowrap;
}

.card-meta {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: end;
    gap: 16px;
    margin-bottom: 14px;
}

.card-meta > div {
    min-width: 0;
}

.card-label {
    display: block;
    margin-bottom: 2px;
    font-size: 0.62rem;
    letter-spacing: 0.5px;
    opacity: 0.75;
}

.card-holder {
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-value {
    font-weight: 600;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

.card-balance-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(127, 127, 127, 0.3);
}

.card-balance {
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
}

.card-chip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

/* Tap-to-copy values on the card */
.copyable {
    display: inline-block;
    max-width: 100%;
    padding: 2px 5px;
    margin: -2px -5px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.card-holder.copyable {
    display: block;
}

.copyable:active,
.copyable.copied {
    background: var(--badge-bg, rgba(255, 255, 255, 0.25));
}

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--badge-bg, rgba(255, 255, 255, 0.2));
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--status);
    box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.75);
}

/* ---------- Floating action button ---------- */

.fab-btn {
    position: absolute;
    right: 24px;
    bottom: calc(24px + var(--safe-bottom));
    z-index: 3;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary);
    color: #fff;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.45);
    transition: transform 0.2s, background-color 0.2s, opacity 0.2s;
}

.fab-btn:hover {
    transform: scale(1.08);
    background-color: var(--primary-hover);
}

/* The FAB belongs to the home screen only */
.app-container.slide-active .fab-btn {
    opacity: 0;
    transform: scale(0.6);
    pointer-events: none;
}

/* ---------- Credentials box ---------- */

.card-credentials-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.credentials-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    text-align: left;
}

.cred-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.cred-toggle-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cred-chevron {
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: transform 0.25s;
}

.card-credentials-box.open .cred-chevron {
    transform: rotate(180deg);
}

.cred-body {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.card-credentials-box.open .cred-body {
    display: flex;
}

.cred-edit-row {
    display: flex;
    justify-content: flex-end;
}

.vendor-badge {
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--border);
    padding: 2px 8px;
    border-radius: 4px;
}

.credential-row {
    display: flex;
    align-items: flex-end;   /* copy button lines up with the input, not the label */
    gap: 8px;
    min-width: 0;
}

.credential-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;   /* expiry left, CVV right, always side by side */
    gap: 12px;
}

.cred-right .cred-info label,
.cred-right .cred-input {
    text-align: right;
}

.cred-info {
    flex: 1;
    min-width: 0;
}

.cred-info label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.cred-input {
    width: 100%;
    min-width: 0;
    height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-weight: 600;
    font-size: 0.9rem;
}

.cred-input[readonly] {
    background: var(--bg-main);
    color: #374151;
    /* stops the browser's own text-selection menu hijacking the long-press */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* ---------- Color picker ---------- */

.field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-group .field-label {
    font-size: 0.78rem;
    margin-bottom: 0;
}

.optional {
    font-weight: 400;
    opacity: 0.8;
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.swatch {
    width: 30px;
    height: 30px;
    padding: 0;
    border: 2px solid rgba(0, 0, 0, 0.12);
    border-radius: 50%;
    background: var(--card-bg);
    transition: transform 0.15s, box-shadow 0.15s;
}

.swatch:hover {
    transform: scale(1.1);
}

.swatch.selected {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
}

.swatch:disabled {
    cursor: default;
    transform: none;
}

.color-picker.disabled {
    opacity: 0.6;
}

/* ---------- Balance ---------- */

.balance-card {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 20px;
}

.balance-card > span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.balance-edit-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.balance-edit-wrapper h2 {
    font-size: 1.3rem;
    color: var(--success);
}

.balance-edit-wrapper h2.negative {
    color: var(--danger);
}

/* ---------- Transactions ---------- */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.transactions-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.empty-note {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
}

.swipeable-container {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    background-color: var(--danger);
}

.swipeable-actions {
    position: absolute;
    inset: 0 0 0 auto;
    display: flex;
    z-index: 1;
}

.action-btn {
    width: 60px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    color: #fff;
    font-size: 1.1rem;
}

.action-btn.edit   { background-color: var(--warning); }
.action-btn.delete { background-color: var(--danger); }

.swipeable-content {
    position: relative;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: transform 0.2s ease-out;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.swipeable-content.open {
    transform: translateX(-120px);
}

.swipeable-content.dragging {
    transition: none;
}

.tx-info {
    min-width: 0;
}

.tx-info h4 {
    font-size: 0.9rem;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tx-info span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.tx-amount {
    flex: none;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
}

.tx-amount.expense { color: var(--danger); }
.tx-amount.income  { color: var(--success); }

/* ---------- Form controls ---------- */

.status-select-dropdown {
    padding: 6px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.8rem;
    cursor: pointer;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 12px;
    min-width: 0;
}

.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-row,
.datetime-row {
    display: flex;
    gap: 10px;
}

.form-row > * {
    flex: 1;
    min-width: 0;
}

.datetime-row {
    align-items: stretch;
}

.datetime-row input {
    flex: 1;
}

.datetime-row .btn {
    flex: none;
}

.form-group input,
.form-group select {
    width: 100%;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 1rem; /* 16px+ stops iOS zooming on focus */
}

.input-with-icon {
    position: relative;
}

.input-with-icon input {
    padding-right: 56px;
}

.card-brand-preview {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    pointer-events: none;
}

.card-brand-preview svg {
    display: block;
    width: 36px;
    height: 24px;
}

/* ---------- Buttons ---------- */

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: background-color 0.2s;
}

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text-dark); }
.btn-secondary:hover { background: #d1d5db; }
.btn-block { width: 100%; }
.btn-sm    { padding: 6px 12px; font-size: 0.8rem; }

.hidden {
    display: none !important;
}

/* ---------- Modals ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--pad);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0s linear 0.25s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s, visibility 0s;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    max-height: 100%;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--pad);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    padding: 4px 8px;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + var(--safe-bottom));
    z-index: 200;
    max-width: calc(100vw - 40px);
    padding: 10px 20px;
    border-radius: 20px;
    background: var(--text-dark);
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translate(-50%, 100px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* ---------- Small phones ---------- */

@media (max-width: 360px) {
    :root { --pad: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
    }
}

/* Make any selection invisible */
::selection {
    background: transparent;
    color: inherit;
}

input:not([readonly])::selection,
textarea::selection {
    background: rgba(79, 70, 229, 0.25);
}
