/* Royal MES Kiosk — Flat design, touch-optimized, mobile-first */
:root {
    --primary: #3b82f6;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --tap-min: 44px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }

/* Login Page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; background: linear-gradient(135deg, #1e293b 0%, #334155 100%); padding: 20px; }
.login-container { background: var(--card-bg); border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-container h1 { text-align: center; font-size: 28px; margin-bottom: 32px; color: #1e293b; }
.login-container h1 span { color: var(--primary); }

.login-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 2px solid var(--border); }
.login-tab { flex: 1; padding: 12px; text-align: center; font-size: 15px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .2s; background: none; border-top: none; border-left: none; border-right: none; min-height: var(--tap-min); }
.login-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
.form-group input, .form-group select { width: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px; font-size: 16px; transition: border-color .2s; background: #fff; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.form-group select { min-height: var(--tap-min); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 24px; border: none; border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; transition: all .15s; width: 100%; min-height: var(--tap-min); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.97); }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text); margin-top: 8px; }
.btn-danger { background: var(--danger); color: #fff; }

.error-msg { background: #fee2e2; color: #991b1b; padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-top: 12px; }

/* Kiosk Main Page */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

header { background: #1e293b; color: #fff; padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; flex-wrap: wrap; gap: 8px; }
.header-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.header-left h1 { font-size: 18px; }
.header-left div { font-size: 12px; color: #cbd5e1; }
.header-left span { color: #fff; font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 8px; }
.header-right button { padding: 8px 14px; background: var(--danger); color: #fff; border: none; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; min-height: var(--tap-min); }

.notification-area { min-width: 160px; }
.notification-area .error { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.notification-area .success { background: #dcfce7; color: #166534; padding: 8px 12px; border-radius: 6px; font-size: 13px; }

.main-container { display: flex; flex: 1; overflow: hidden; }
.left-panel { width: 380px; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; background: #fff; }
.right-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #fff; }

.search-container { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.search-container input { width: 100%; padding: 16px 18px; border: 2px solid var(--border); border-radius: 12px; font-size: 18px; text-align: center; }
.search-container input:focus { outline: none; border-color: var(--primary); }

.order-info { flex: 1; padding: 16px; overflow-y: auto; }
.order-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.order-code { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.order-status { margin-bottom: 12px; }
.order-status p { font-size: 13px; }
.order-stages { margin-bottom: 16px; }
.order-stages p { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }

.image-container { text-align: center; }
.order-thumbnail { max-width: 100%; max-height: 300px; border-radius: 8px; cursor: pointer; }
.thumbnail-placeholder { padding: 60px 20px; color: var(--text-muted); border: 2px dashed var(--border); border-radius: 8px; font-size: 14px; }

.tab-bar { display: flex; border-bottom: 1px solid var(--border); padding: 0 12px; flex-shrink: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-bar button { padding: 14px 14px; border: none; background: none; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; min-height: var(--tap-min); }
.tab-bar button.active { color: var(--primary); border-bottom-color: var(--primary); }

.plan-list { flex: 1; overflow-y: auto; padding: 8px; }
.plan-item { padding: 16px; border-radius: 10px; cursor: pointer; margin-bottom: 6px; transition: background .15s; border: 1px solid var(--border); }
.plan-item:hover { background: #f1f5f9; }
.plan-item div:first-child { font-size: 14px; font-weight: 600; }
.plan-item div:last-child { font-size: 12px; color: var(--text-muted); }

.controls { display: flex; gap: 12px; padding: 12px 16px; padding-bottom: calc(12px + var(--safe-bottom)); background: #fff; border-top: 1px solid var(--border); flex-shrink: 0; }
.controls button { flex: 1; padding: 18px 12px; border: none; border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; transition: all .15s; min-height: var(--tap-min); }
.controls button:active { transform: scale(.97); }

/* Virtual Keyboard */
.virtual-keyboard { position: fixed; bottom: 0; left: 0; right: 0; background: #1e293b; padding: 10px; padding-bottom: calc(10px + var(--safe-bottom)); z-index: 1000; }
.kb-keys { max-width: 800px; margin: 0 auto; }
.kb-row { display: flex; gap: 5px; margin-bottom: 5px; justify-content: center; }
.kb-key { padding: 16px 0; min-width: 44px; border: none; border-radius: 6px; background: #334155; color: #fff; font-size: 18px; cursor: pointer; font-weight: 500; transition: background .1s; }
.kb-key:hover { background: #475569; }
.kb-key:active { background: var(--primary); }

/* Loading */
.loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 999; }
.loading-spinner { width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
.loading-text { color: #fff; margin-top: 12px; font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* QR Code display on kiosk */
.qr-container { text-align: center; padding: 40px 20px; }
.qr-container canvas, .qr-container img { border: 8px solid #fff; border-radius: 12px; box-shadow: var(--shadow); }
.qr-code-text { font-size: 14px; color: var(--text-muted); margin-top: 16px; }
.qr-refresh { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* Pairing page on phone */
.pair-container { max-width: 400px; margin: 24px auto; padding: 16px; }
.pair-card { background: #fff; border-radius: var(--radius); padding: 32px 24px; box-shadow: var(--shadow); text-align: center; }
.pair-card h2 { font-size: 20px; margin-bottom: 16px; }
.pair-card .kiosk-name { font-size: 16px; color: var(--text-muted); margin-bottom: 24px; }
.pair-card .btn { margin-top: 16px; }
.pair-success { color: var(--success); font-size: 48px; margin-bottom: 8px; }

/* Responsive — phone layout */
@media (max-width: 768px) {
    .login-container { margin: 0; padding: 32px 24px; border-radius: 20px; }
    .main-container { flex-direction: column; }
    .left-panel { width: 100%; max-height: 45vh; }
    .right-panel { flex: 1; }
    .controls { flex-wrap: wrap; gap: 8px; }
    .controls button { flex: 1 1 calc(50% - 4px); padding: 16px; font-size: 14px; }
    header { padding: 8px 12px; }
    .header-left { gap: 10px; }
    .header-left h1 { font-size: 16px; }
    .search-container input { padding: 14px; font-size: 16px; }
    .plan-item { padding: 14px; }
    .tab-bar button { padding: 12px 10px; font-size: 12px; }
    .order-thumbnail { max-height: 200px; }
}
@media (max-width: 480px) {
    .login-container { padding: 24px 18px; }
    .login-container h1 { font-size: 24px; margin-bottom: 24px; }
    .controls button { padding: 14px 8px; font-size: 13px; }
    .kb-key { padding: 14px 0; min-width: 36px; font-size: 16px; }
}

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