:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --line: #e4ebe8;
  --text: #17231f;
  --muted: #6d7c77;
  --brand: #0f6b57;
  --brand-dark: #084c3f;
  --brand-soft: #e8f4f0;
  --gold: #c58a2b;
  --danger: #c94545;
  --danger-soft: #fff0f0;
  --warning: #a36811;
  --warning-soft: #fff7e6;
  --success: #16835d;
  --shadow: 0 12px 36px rgba(20, 43, 35, .08);
  --radius: 16px;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(380px, 560px);
  padding: clamp(24px, 5vw, 72px);
  gap: 48px;
  align-items: center;
  background:
    radial-gradient(circle at 12% 18%, rgba(216, 177, 100, .18), transparent 30%),
    linear-gradient(135deg, #092e27 0 52%, #f3f6f5 52% 100%);
}

.login-brand { color: #fff; display: flex; align-items: center; gap: 18px; justify-self: center; }
.login-brand strong { display: block; font-size: clamp(26px, 3vw, 46px); letter-spacing: .06em; }
.login-brand span { display: block; margin-top: 8px; color: rgba(255,255,255,.65); font-size: 18px; letter-spacing: .28em; }

.login-card { width: 100%; max-width: 480px; justify-self: center; padding: 42px; border-radius: 24px; background: #fff; box-shadow: 0 30px 80px rgba(0,0,0,.14); }
.login-card header { margin-bottom: 32px; }
.eyebrow { margin: 0 0 8px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.login-card h1 { margin: 0; font-size: 30px; }
.login-card header > p:last-child { margin: 10px 0 0; color: var(--muted); }
label { display: grid; gap: 8px; color: #42524d; font-size: 14px; font-weight: 650; }
.login-card label + label { margin-top: 18px; }
input, select, textarea { width: 100%; border: 1px solid #dce5e1; border-radius: 10px; background: #fff; color: var(--text); outline: none; transition: .18s ease; }
input, select { min-height: 42px; padding: 0 12px; }
textarea { min-height: 92px; padding: 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,107,87,.1); }
.form-message { min-height: 20px; margin: 14px 0 0; color: var(--danger); text-align: center; font-size: 13px; }

.button { min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px; font-weight: 700; transition: .18s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--brand); box-shadow: 0 7px 18px rgba(15,107,87,.2); }
.button.primary:hover { background: var(--brand-dark); }
.button.secondary { color: var(--brand); background: var(--brand-soft); }
.button.ghost { border: 1px solid var(--line); color: #3d4d47; background: #fff; }
.button.danger { color: var(--danger); background: var(--danger-soft); }
.button.small { min-height: 32px; padding: 0 11px; font-size: 13px; }
.button.full { width: 100%; min-height: 48px; margin-top: 28px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 30; height: 100vh; display: flex; flex-direction: column; color: #fff; background: #0b322a; }
.sidebar-brand { min-height: 82px; padding: 18px; display: flex; gap: 12px; align-items: center; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 15px; }
.sidebar-brand span { margin-top: 3px; color: rgba(255,255,255,.58); font-size: 12px; }
.sidebar-close { display: none; margin-left: auto; color: #fff; }
.nav-list { flex: 1; padding: 16px 12px; overflow: auto; }
.nav-section { margin: 16px 12px 8px; color: rgba(255,255,255,.36); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.nav-item { width: 100%; min-height: 42px; margin: 3px 0; padding: 0 12px; display: flex; align-items: center; gap: 11px; border: 0; border-radius: 10px; color: rgba(255,255,255,.74); background: transparent; text-align: left; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-item.active { color: #fff; background: rgba(255,255,255,.12); box-shadow: inset 3px 0 #dfb35d; }
.nav-icon { width: 22px; text-align: center; font-size: 15px; }
.nav-badge { margin-left: auto; min-width: 21px; padding: 2px 6px; border-radius: 99px; background: #d6a34b; color: #16332b; font-size: 10px; font-weight: 800; text-align: center; }
.sidebar-footer { margin: 12px; padding: 13px; display: flex; gap: 10px; align-items: center; border: 1px solid rgba(255,255,255,.08); border-radius: 12px; background: rgba(255,255,255,.04); }
.sidebar-footer strong, .sidebar-footer small { display: block; }
.sidebar-footer strong { font-size: 12px; }
.sidebar-footer small { margin-top: 3px; color: rgba(255,255,255,.45); font-size: 10px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #45d398; box-shadow: 0 0 0 4px rgba(69,211,152,.12); }

.main-shell { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 82px; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.93); backdrop-filter: blur(12px); }
.topbar-left { display: flex; gap: 12px; align-items: center; }
.topbar h1 { margin: 0; font-size: 21px; }
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.menu-button { display: none; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 0; border-radius: 10px; color: #52615c; background: transparent; font-size: 20px; }
.icon-button:hover { background: var(--surface-soft); }
.topbar-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.account-button { min-width: 176px; padding: 5px 8px; display: flex; align-items: center; gap: 9px; border: 0; border-radius: 12px; background: transparent; text-align: left; }
.account-button:hover { background: var(--surface-soft); }
.account-button span:nth-child(2) { flex: 1; }
.account-button strong, .account-button small { display: block; }
.account-button strong { font-size: 13px; }
.account-button small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.account-menu { position: absolute; top: 52px; right: 0; width: 160px; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); }
.account-menu button { width: 100%; min-height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; }
.account-menu button:hover { background: var(--surface-soft); }

.content { min-width: 0; padding: 26px 28px 48px; overflow-x: hidden; }
.page-stack { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.page-header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-header-row h2 { margin: 0; font-size: 18px; }
.page-header-row p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.metric-grid { width: 100%; min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { position: relative; min-width: 0; min-height: 128px; padding: 20px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 4px 18px rgba(30,55,47,.03); }
.metric-card::after { content: ""; position: absolute; right: -30px; bottom: -45px; width: 110px; height: 110px; border-radius: 50%; background: var(--brand-soft); }
.metric-card .metric-label { position: relative; z-index: 1; color: var(--muted); font-size: 12px; }
.metric-card strong { position: relative; z-index: 1; display: block; margin-top: 13px; font-size: clamp(22px, 2.4vw, 31px); letter-spacing: -.03em; }
.metric-card small { position: relative; z-index: 1; display: block; margin-top: 8px; color: var(--success); font-size: 11px; }
.metric-card small.down { color: var(--danger); }
.grid-2 { width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .75fr); gap: 16px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 4px 18px rgba(30,55,47,.025); }
.panel-header { min-height: 60px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.panel-body { padding: 18px; }
.chart { height: 250px; display: flex; align-items: end; gap: 12px; padding: 18px 8px 0; }
.bar-group { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: end; align-items: center; gap: 8px; }
.bar-track { width: min(38px, 70%); height: 190px; display: flex; align-items: end; border-radius: 8px 8px 3px 3px; background: #f0f4f2; overflow: hidden; }
.bar { width: 100%; min-height: 3px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, #249179, var(--brand)); }
.bar-group span { color: var(--muted); font-size: 10px; }
.rtp-gauge { width: 182px; height: 182px; margin: 8px auto 18px; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--brand) 0 96.4%, #e7eeeb 96.4% 100%); }
.rtp-gauge::before { content: ""; width: 142px; height: 142px; border-radius: 50%; background: #fff; }
.rtp-gauge div { position: absolute; text-align: center; }
.rtp-gauge strong { display: block; font-size: 31px; }
.rtp-gauge span { color: var(--muted); font-size: 11px; }
.summary-list { display: grid; gap: 12px; }
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.summary-row span { color: var(--muted); font-size: 12px; }
.summary-row strong { font-size: 13px; }

.filter-bar { padding: 14px; display: grid; grid-template-columns: minmax(180px, 1fr) repeat(3, minmax(130px, .45fr)) auto; gap: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.search-box { position: relative; }
.search-box::before { content: "⌕"; position: absolute; left: 12px; top: 50%; transform: translateY(-53%); color: var(--muted); font-size: 20px; }
.search-box input { padding-left: 36px; }
.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
th { color: var(--muted); background: var(--surface-soft); font-size: 10px; letter-spacing: .04em; }
tbody tr:hover { background: #fbfcfc; }
tbody tr:last-child td { border-bottom: 0; }
.cell-title { display: flex; align-items: center; gap: 10px; }
.cell-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: var(--brand); background: var(--brand-soft); font-weight: 800; }
.cell-title strong, .cell-title small { display: block; }
.cell-title small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.money.positive { color: var(--success); }
.money.negative { color: var(--danger); }
.tag { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 0 9px; border-radius: 99px; color: #49615a; background: #eef3f1; font-size: 10px; font-weight: 700; }
.tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.tag.active { color: var(--success); background: #e9f7f1; }
.tag.offline { color: #77837f; background: #eff2f1; }
.tag.warning { color: var(--warning); background: var(--warning-soft); }
.tag.danger { color: var(--danger); background: var(--danger-soft); }
.table-actions { display: flex; gap: 5px; }
.table-link { padding: 3px 5px; border: 0; color: var(--brand); background: transparent; font-size: 11px; font-weight: 700; }
.table-link:hover { text-decoration: underline; }
.pagination { min-height: 56px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.pagination-buttons { display: flex; gap: 5px; }
.pagination-buttons button { min-width: 31px; height: 31px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #52615c; }
.pagination-buttons button.active { color: #fff; border-color: var(--brand); background: var(--brand); }

.rtp-layout { display: grid; grid-template-columns: minmax(280px, .75fr) minmax(0, 1.6fr); gap: 16px; }
.rtp-master { padding: 22px; color: #fff; background: linear-gradient(140deg, #0b4f41, #117460); }
.rtp-master .eyebrow { color: #e8c67c; }
.rtp-master h3 { margin: 5px 0 0; font-size: 20px; }
.rtp-master p { margin: 9px 0 22px; color: rgba(255,255,255,.68); font-size: 12px; line-height: 1.7; }
.rtp-value { display: flex; align-items: end; gap: 6px; }
.rtp-value strong { font-size: 52px; letter-spacing: -.05em; }
.rtp-value span { padding-bottom: 9px; color: rgba(255,255,255,.6); }
.rtp-master .button { margin-top: 22px; background: #fff; color: var(--brand-dark); }
.priority-list { display: grid; gap: 8px; margin-top: 18px; }
.priority-item { padding: 13px; display: flex; gap: 11px; align-items: center; border: 1px solid var(--line); border-radius: 11px; }
.priority-number { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: var(--brand); background: var(--brand-soft); font-size: 12px; font-weight: 800; }
.priority-item strong, .priority-item small { display: block; }
.priority-item strong { font-size: 12px; }
.priority-item small { margin-top: 3px; color: var(--muted); font-size: 10px; }

.machine-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.machine-card { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.machine-card header { display: flex; justify-content: space-between; gap: 10px; }
.machine-code { margin-top: 2px; font-family: Consolas, monospace; font-size: 13px; }
.machine-card h3 { margin: 18px 0 4px; font-size: 15px; }
.machine-card > p { margin: 0; color: var(--muted); font-size: 11px; }
.machine-stats { margin: 16px 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.machine-stats div { padding: 10px; border-radius: 10px; background: var(--surface-soft); }
.machine-stats span, .machine-stats strong { display: block; }
.machine-stats span { color: var(--muted); font-size: 9px; }
.machine-stats strong { margin-top: 4px; font-size: 13px; }
.machine-card footer { display: flex; justify-content: space-between; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-note { margin: 0; padding: 12px; border-radius: 10px; color: #53645e; background: var(--surface-soft); font-size: 11px; line-height: 1.65; }
.switch-row { min-height: 48px; padding: 10px 0; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row strong, .switch-row small { display: block; }
.switch-row strong { font-size: 12px; }
.switch-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.switch { width: 42px; height: 24px; padding: 3px; border: 0; border-radius: 99px; background: #cbd6d2; }
.switch::after { content: ""; display: block; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 5px rgba(0,0,0,.2); transition: .18s ease; }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(18px); }
.empty-state { padding: 60px 20px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--text); }

.modal-layer { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-mask { position: absolute; inset: 0; background: rgba(5, 22, 18, .55); backdrop-filter: blur(4px); }
.modal { position: relative; width: min(620px, 100%); max-height: min(780px, calc(100vh - 40px)); display: flex; flex-direction: column; border-radius: 18px; background: #fff; box-shadow: 0 30px 100px rgba(0,0,0,.24); overflow: hidden; }
.modal-header { min-height: 72px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 19px; }
.modal-body { padding: 20px; overflow: auto; }
.modal-footer { min-height: 66px; padding: 12px 20px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 150; display: grid; gap: 8px; }
.toast { min-width: 260px; padding: 13px 16px; border-radius: 11px; color: #fff; background: #193f35; box-shadow: var(--shadow); font-size: 12px; animation: toast-in .22s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.sidebar-mask { display: none; }

@media (max-width: 1160px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .machine-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: 1fr repeat(2, minmax(120px, .45fr)); }
  .filter-bar > :nth-child(4) { display: none; }
}

@media (max-width: 880px) {
  .login-shell { grid-template-columns: 1fr; background: linear-gradient(160deg, #092e27 0 35%, #f3f6f5 35% 100%); }
  .login-brand { justify-self: start; }
  .login-brand strong { font-size: 25px; }
  .login-brand span { font-size: 13px; }
  .login-card { padding: 30px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 260px; transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .menu-button { display: inline-grid; }
  .sidebar-mask { position: fixed; inset: 0; z-index: 25; background: rgba(4,19,16,.42); }
  .sidebar-mask.open { display: block; }
  .grid-2, .rtp-layout { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar .search-box { grid-column: 1 / -1; }
  .filter-bar > :nth-child(4) { display: block; }
}

@media (max-width: 620px) {
  .login-shell { padding: 24px 16px; gap: 24px; }
  .login-brand { justify-self: center; }
  .topbar { min-height: 70px; padding: 10px 14px; }
  .topbar h1 { font-size: 17px; }
  .topbar p, .account-button span:nth-child(2), .account-button b, #refreshPage { display: none; }
  .account-button { min-width: 0; padding: 0; }
  .main-shell { width: 100vw; max-width: 100vw; overflow: hidden; }
  .content { width: 100%; max-width: 100vw; padding: 16px 12px 32px; }
  .page-stack { width: 100%; max-width: calc(100vw - 24px); }
  .page-header-row { align-items: flex-start; flex-direction: column; }
  .metric-grid { width: 100%; max-width: calc(100vw - 24px); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric-card { min-height: 108px; padding: 15px; }
  .metric-card strong { font-size: 21px; }
  .panel-body { padding: 14px; }
  .chart { gap: 4px; padding-inline: 0; }
  .bar-group span { font-size: 8px; }
  .machine-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-bar .search-box { grid-column: auto; }
  .filter-bar > * { display: block !important; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .modal-layer { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; }
  .toast-region { right: 12px; bottom: 12px; left: 12px; }
  .toast { min-width: 0; }
  th, td { padding: 12px; }
}
