/* ==========================================================
   Toby Bros POS — Base Styles
   Reset, typography, utility classes
   ========================================================== */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    height: 100%;
    touch-action: manipulation; /* disable double-tap zoom on touch */
}

body {
    font-family: var(--font);
    font-size: var(--text-base);
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.5;
    height: 100%;
    overflow: hidden; /* POS is a fixed-layout app */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none; /* touchscreen — no text selection */
}

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

/* A visible keyboard focus is essential on shared tills with keyboards. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid #FFFFFF;
    outline-offset: 2px;
    box-shadow: 0 0 0 5px var(--brand-info);
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Allow text selection in inputs */
input, textarea, [contenteditable] {
    user-select: text;
}

/* ---- Links ---- */
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Typography ---- */
h1 { font-size: var(--text-2xl); font-weight: var(--fw-bold); }
h2 { font-size: var(--text-xl);  font-weight: var(--fw-semi); }
h3 { font-size: var(--text-lg);  font-weight: var(--fw-semi); }
h4 { font-size: var(--text-base);font-weight: var(--fw-medium); }

.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-lg    { font-size: var(--text-lg); }
.text-xl    { font-size: var(--text-xl); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-danger  { color: var(--brand-danger); }
.text-success { color: var(--brand-primary); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-bold  { font-weight: var(--fw-bold); }
.fw-semi  { font-weight: var(--fw-semi); }
.fw-medium { font-weight: var(--fw-medium); }
.font-mono { font-family: var(--font-mono); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: var(--text-base);
    font-weight: var(--fw-semi);
    cursor: pointer;
    transition: filter var(--transition), transform var(--transition);
    text-decoration: none;
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;   /* Apple HIG minimum tap target */
}
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn[disabled] {
    background: var(--btn-disabled-bg) !important;
    color: var(--btn-disabled-text) !important;
    cursor: not-allowed;
    transform: none;
    opacity: 0.82;
}

.btn-primary   { background: var(--btn-primary-bg);   color: var(--btn-primary-text); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-text); border: 1.5px solid var(--btn-secondary-border); }
.btn-danger    { background: var(--btn-danger-bg);    color: var(--btn-danger-text); }
.btn-warning   { background: var(--btn-warning-bg);   color: var(--btn-warning-text); }
.btn-ghost     { background: transparent; color: var(--text-secondary); border: 1.5px solid var(--border); }

.btn:hover:not(:disabled) { filter: brightness(1.08); }

.btn-lg { padding: 14px 24px; font-size: var(--text-lg); min-height: 52px; border-radius: var(--radius); }
.btn-sm { padding: 6px 12px; font-size: var(--text-sm); min-height: 36px; }
.btn-icon { padding: 10px; min-width: 44px; }
.btn-full { width: 100%; }
.btn-round { border-radius: 99px; }

/* ---- Inputs ---- */
.input {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1.5px solid var(--input-border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: var(--text-base);
    color: var(--text-primary);
    transition: border-color var(--transition);
    min-height: 44px;
    outline: none;
}
.input:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--input-focus) 15%, transparent);
}
.input:focus-visible {
    outline: 2px solid #FFFFFF;
    outline-offset: 1px;
    box-shadow: 0 0 0 4px var(--brand-info);
}
.input::placeholder { color: var(--text-muted); }
.input-lg { padding: 14px 16px; font-size: var(--text-lg); min-height: 52px; }
textarea.input { resize: vertical; min-height: 88px; }
select.input { cursor: pointer; }
input[type="checkbox"], input[type="radio"] {
    accent-color: var(--btn-primary-bg);
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

/* ---- Shared forms and alerts (used by both POS and admin pages) ---- */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label,
label.form-group { font-size: var(--text-sm); font-weight: var(--fw-medium); color: var(--text-secondary); }
.form-group .hint { font-size: var(--text-xs); color: var(--text-muted); }

.alert {
    padding: 12px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    line-height: 1.45;
}
.alert-warning { background: #FFF3E0; border-color: #E7A56E; color: #7A3600; }
.alert-danger  { background: #FFEBEE; border-color: #E5A4AA; color: #8E1111; }
.alert-success { background: #E8F5E9; border-color: #9BC69D; color: #1B5E20; }
.alert-info    { background: #E3F2FD; border-color: #90BDD8; color: #005987; }
[data-theme="dark"] .alert-warning { background: #3D280D; border-color: #7B572C; color: #FFD19A; }
[data-theme="dark"] .alert-danger  { background: #401B1E; border-color: #7A3A40; color: #FFB3B3; }
[data-theme="dark"] .alert-success { background: #17391B; border-color: #356A3A; color: #A5D6A7; }
[data-theme="dark"] .alert-info    { background: #123247; border-color: #285C78; color: #9DD6F5; }

/* ---- Badges & Tags ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: var(--text-xs);
    font-weight: var(--fw-semi);
    white-space: nowrap;
}
.badge-gst-free { background: var(--tag-gst-free); color: var(--tag-gst-free-text); }
.badge-member   { background: var(--tag-member);   color: var(--tag-member-text); }
.badge-green    { background: #E8F5E9; color: #2E7D32; }
.badge-red      { background: #FFEBEE; color: #C62828; }
.badge-amber    { background: #FFF8E1; color: #8A4700; }
.badge-info     { background: #E3F2FD; color: #00649B; }

/* ---- Cards / Surfaces ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* ---- Divider ---- */
.divider {
    height: 1px;
    background: var(--border);
    margin: var(--gap) 0;
}

/* ---- Overlay ---- */
.overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: var(--z-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 120ms ease;
}
@keyframes fadeIn { from { opacity: 0; } }

/* ---- Modal ---- */
.modal {
    background: var(--modal-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: min(540px, 96vw);
    max-height: 92vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    animation: slideUp 180ms ease;
    overscroll-behavior: contain;
}
.modal-lg  { width: min(700px, 96vw); }
.modal-xl  { width: min(900px, 96vw); }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--modal-header);
    color: var(--modal-header-text);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
}
.modal-header h2 { font-size: var(--text-xl); color: inherit; }
.modal-header .btn-ghost {
    color: var(--modal-header-text);
    border-color: rgba(255,255,255,0.45);
    background: rgba(255,255,255,0.10);
}
.modal-header .btn-ghost:hover { background: rgba(255,255,255,0.20); }
.modal-body  { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: var(--gap);
    justify-content: flex-end;
    flex-shrink: 0;
    flex-wrap: wrap;
}

body.modal-open { overflow: hidden !important; }

/* ---- Toast notifications ---- */
#toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: min(460px, calc(100vw - 24px));
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: var(--fw-semi);
    color: #fff;
    min-width: 240px;
    text-align: center;
    animation: toastIn 200ms ease;
    pointer-events: all;
    box-shadow: var(--shadow-lg);
    width: fit-content;
    max-width: 100%;
}
.toast-success { background: var(--toast-success); }
.toast-error   { background: var(--toast-error); }
.toast-warning { background: var(--toast-warning); }
.toast-info    { background: var(--toast-info); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---- Spinner ---- */
.spinner {
    width: 22px; height: 22px;
    border: 3px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Empty state ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--gap);
    padding: 48px var(--gap);
    color: var(--text-muted);
    text-align: center;
}
.empty-state .icon { font-size: 3rem; opacity: 0.4; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Utilities ---- */
.hidden   { display: none !important; }
.invisible { visibility: hidden; }
.flex     { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-sm   { gap: var(--gap-sm); }
.gap      { gap: var(--gap); }
.gap-lg   { gap: var(--gap-lg); }
.flex-1   { flex: 1; }
.w-full   { width: 100%; }
.p        { padding: var(--gap); }
.p-lg     { padding: var(--gap-lg); }
.p-sm     { padding: var(--gap-sm); }
.mt       { margin-top: var(--gap); }
.mt-sm    { margin-top: var(--gap-sm); }
.mt-lg    { margin-top: var(--gap-lg); }
.mb       { margin-bottom: var(--gap); }
.mb-sm    { margin-bottom: var(--gap-sm); }
.mb-lg    { margin-bottom: var(--gap-lg); }
.ml       { margin-left: var(--gap); }
.ml-auto  { margin-left: auto; }
.mr-sm    { margin-right: var(--gap-sm); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Connection status dot ---- */
.connection-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: var(--online-color);
    transition: background var(--transition-slow);
}
.connection-dot.offline { background: var(--offline-color); }

/* ---- PIN pad ---- */
.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
}
.pin-pad .btn {
    aspect-ratio: 1;
    font-size: var(--text-xl);
    font-weight: var(--fw-bold);
}

/* ---- Numeric keypad ---- */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.numpad .btn {
    padding: 14px;
    font-size: var(--text-xl);
    font-weight: var(--fw-bold);
    background: var(--surface-2);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.numpad .btn:active { background: var(--surface-3); }
.numpad .btn-danger { background: var(--btn-danger-bg); color: #fff; border-color: transparent; }
.numpad .btn-primary { background: var(--btn-primary-bg); color: #fff; border-color: transparent; }

@media (max-width: 600px) {
    .overlay {
        align-items: flex-end;
        padding-top: max(10px, env(safe-area-inset-top));
    }
    .modal,
    .modal-lg,
    .modal-xl {
        width: 100%;
        max-height: calc(100dvh - max(10px, env(safe-area-inset-top)));
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
    .modal-header { border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 14px 16px; }
    .modal-header h2 { font-size: var(--text-lg); }
    .modal-body { padding: 16px; }
    .modal-footer {
        padding: 12px 16px max(12px, env(safe-area-inset-bottom));
        background: var(--modal-bg);
    }
    .modal-footer .btn { flex: 1 1 120px; }
    #toast-container { bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (pointer: coarse) {
    input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
