/* =============================================================
   Gerenciador de Documentos  -  Mobile-first
   ============================================================= */
:root{
  --bg:         #f5f7fa;
  --surface:    #ffffff;
  --surface-2:  #f0f3f8;
  --border:     #e1e6ed;
  --text:       #1a1f2c;
  --text-soft:  #5b6573;
  --primary:    #2f6bff;
  --primary-dk: #1e52d8;
  --accent:     #0ec48c;
  --danger:     #e64646;
  --warn:       #ffb020;
  --shadow-sm:  0 1px 3px rgba(20,30,60,.08);
  --shadow:     0 4px 16px rgba(20,30,60,.12);
  --radius:     12px;
  --nav-h:      66px;
  --topbar-h:   56px;
}
*,*::before,*::after{ box-sizing:border-box; -webkit-tap-highlight-color: transparent; }
html,body{ margin:0; padding:0; height:100%; overscroll-behavior-y: contain; }
body{
  font-family: 'Inter','Segoe UI',system-ui,-apple-system,sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden{ display:none !important; }

/* ============ LOGIN ============ */
.login-screen{
  position:fixed; inset:0;
  display:grid; place-items:center;
  background: linear-gradient(135deg,#2f6bff 0%, #1e52d8 60%, #16307a 100%);
  padding: 20px;
}
.login-box{
  width:100%; max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display:flex; flex-direction:column; gap: 14px;
}
.login-logo{ text-align:center; margin-bottom: 4px; }
.login-logo h1{ margin: 12px 0 4px; font-size: 20px; }
.login-logo p{ margin: 0; color: var(--text-soft); font-size: 14px; }
.login-box label{
  display:flex; flex-direction:column; gap:6px;
  font-size: 12px; color: var(--text-soft); font-weight: 600;
}
.login-box input{
  padding: 14px 16px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 16px; outline:none;
  -webkit-appearance: none;
}
.login-box input:focus{ border-color: var(--primary); }
.login-hint{ text-align:center; color: var(--text-soft); }
.logo-icon{
  width: 60px; height: 60px;
  border-radius: 16px;
  background: linear-gradient(135deg,#2f6bff,#0ec48c);
  color:#fff;
  display:inline-flex; align-items:center; justify-content:center;
  font-weight: 800; letter-spacing: 1px;
}
.logo-icon.sm{ width: 36px; height: 36px; border-radius: 9px; font-size: 12px; }

/* ============ APP layout — MOBILE ============ */
.app{
  display:flex; flex-direction:column;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

.sidebar{
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display:flex; flex-direction: row;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 16px rgba(0,0,0,.05);
}
.brand{ display:none; }
.nav{
  flex:1;
  display:flex; flex-direction:row;
  padding: 4px 2px; gap: 0;
  overflow-x: auto;
}
.nav-item{
  flex: 1; min-width: 60px;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap: 2px;
  background: transparent; border:0;
  color: var(--text-soft);
  padding: 6px 4px;
  font-size: 10px;
  cursor:pointer; text-align:center;
  border-radius: 8px;
  min-height: 56px;
}
.nav-item .icon{ font-size: 20px; line-height: 1; }
.nav-item.active{ color: var(--primary); background: rgba(47,107,255,.08); }
.sidebar-footer{ display:none; }

.main{ flex:1; display:flex; flex-direction:column; min-width: 0; }
.topbar{
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  display:flex; align-items:center; justify-content:space-between;
  gap: 8px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2{ margin:0; font-size: 17px; font-weight: 600; flex: 1; min-width: 0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.topbar-actions{ display:flex; gap: 6px; flex-shrink: 0; }
.view-area{ padding: 14px; }

/* ============ BUTTONS (touch friendly) ============ */
.btn{
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor:pointer; font-weight: 500;
  display:inline-flex; align-items:center; justify-content:center;
  gap: 6px;
  min-height: 44px;
  transition: all .15s ease;
}
.btn:active{ transform: scale(.97); }
.btn.primary{ background: var(--primary); color:#fff; border-color: var(--primary); }
.btn.primary:active{ background: var(--primary-dk); }
.btn.danger { background: var(--danger);  color:#fff; border-color: var(--danger); }
.btn.ghost  { background: transparent; color: var(--text-soft); }
.btn.block  { width: 100%; }
.btn.sm     { padding: 6px 12px; font-size: 13px; min-height: 36px; }
.icon-btn{
  background: transparent; border:0; color: var(--text-soft);
  width: 44px; height: 44px; border-radius: 8px; cursor:pointer;
  font-size: 22px; line-height: 1;
}
.topbar .btn{ padding: 8px 12px; min-height: 38px; font-size: 13px; }

/* ============ CARDS (dashboard) ============ */
.cards{
  display:grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.card{
  background: var(--surface); border:1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-sm);
}
.card .label{ color: var(--text-soft); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.card .value{ font-size: 24px; font-weight: 700; margin-top: 4px; }
.card .sub  { color: var(--text-soft); font-size: 12px; margin-top: 2px; }

.panel{
  background: var(--surface); border:1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  overflow:hidden; margin-bottom: 12px;
}
.panel-head{
  padding: 12px 14px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between;
  background: var(--surface-2);
}
.panel-head h3{ margin:0; font-size: 14px; font-weight: 600; }
.panel-body{ padding: 14px; }
.panel-body.flush{ padding: 0; }

/* ============ TABLE → CARD LIST (mobile) ============ */
.table{ width:100%; border-collapse: collapse; display:block; }
.table thead{ display: none; }
.table tbody, .table tr, .table td{ display: block; width: 100%; }
.table tr{
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  position: relative;
}
.table tr:last-child{ border-bottom: 0; }
.table td{
  padding: 4px 0;
  font-size: 14px;
  border: none;
  text-align: left;
}
.table td:before{
  content: attr(data-label);
  display: inline-block;
  min-width: 100px;
  color: var(--text-soft);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: .3px;
}
.table td:first-child{ font-size: 16px; margin-bottom: 4px; }
.table td:first-child:before{ display: none; }
.table td.actions{
  display:flex; flex-wrap:wrap; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border);
}
.table td.actions:before{ display: none; }
.table td.actions .btn{ flex: 1; min-width: 88px; }

.empty-state{
  padding: 40px 20px; text-align:center; color: var(--text-soft);
}
.empty-state .icon{ font-size: 38px; opacity: .4; }
.empty-state p{ margin: 8px 0 0; }

/* ============ TOOLBAR ============ */
.toolbar{
  display:flex; flex-direction: column;
  gap: 8px; margin-bottom: 12px;
}
.toolbar input, .toolbar select{
  padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; background: var(--surface); width: 100%;
  -webkit-appearance: none;
}
.toolbar input:focus, .toolbar select:focus{ outline:none; border-color: var(--primary); }

/* ============ FORM ============ */
.form{ display:flex; flex-direction: column; gap: 12px; }
.form .row{ display:flex; flex-direction:column; gap: 12px; }
.form label{
  display:flex; flex-direction:column; gap: 6px;
  font-size: 12px; color: var(--text-soft); font-weight: 600;
}
.form input, .form select, .form textarea{
  padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; background: var(--surface); font-family: inherit;
  -webkit-appearance: none;
}
.form input:focus, .form select:focus, .form textarea:focus{
  outline:none; border-color: var(--primary);
}
.form textarea{ resize: vertical; min-height: 80px; }
.form input[type=file]{ padding: 10px 12px; font-size: 14px; }

/* ============ CHIPS ============ */
.chip{
  display:inline-flex; align-items:center; gap:4px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-soft);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.chip.exame{     background: #fef3c7; color: #92400e; }
.chip.documento{ background: #dbeafe; color: #1e3a8a; }
.chip.consulta{  background: #e0e7ff; color: #3730a3; }
.chip.relatorio{ background: #d1fae5; color: #065f46; }
.chip.receita  { background: #fce7f3; color: #9d174d; }
.chip.realizada{ background: #d1fae5; color: #065f46; }
.chip.agendada{  background: #dbeafe; color: #1e3a8a; }
.chip.cancelada{ background: #fee2e2; color: #991b1b; }
.chip.em.uso   { background: #d1fae5; color: #065f46; }
.chip.suspensa { background: #f3f4f6; color: #4b5563; }
.chip.inativa  { background: #f3f4f6; color: #4b5563; }
.chip.ativa    { background: #d1fae5; color: #065f46; }

/* ============ FILE PILLS ============ */
.file-pill{
  display:inline-flex; align-items:center; gap:6px;
  padding: 5px 10px; border-radius: 6px;
  background: var(--surface-2); border:1px solid var(--border);
  font-size: 12px; margin: 2px; text-decoration: none; color: var(--text);
}

/* ============ TIMELINE ============ */
.timeline{ position: relative; padding-left: 22px; }
.timeline::before{
  content:''; position:absolute; left: 8px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-item{
  position: relative; padding: 12px 14px;
  background: var(--surface); border:1px solid var(--border);
  border-radius: 10px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.tl-item::before{
  content:''; position:absolute; left: -19px; top: 16px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--primary);
}
.tl-item.exame::before    { background: var(--warn);    box-shadow: 0 0 0 2px var(--warn); }
.tl-item.documento::before{ background: var(--primary); }
.tl-item.consulta::before { background: #6366f1;        box-shadow: 0 0 0 2px #6366f1; }
.tl-item.relatorio::before{ background: var(--accent);  box-shadow: 0 0 0 2px var(--accent); }
.tl-item.receita::before  { background: #db2777;        box-shadow: 0 0 0 2px #db2777; }
.tl-item .date{ color: var(--text-soft); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tl-item h4{ margin: 4px 0; font-size: 15px; }
.tl-item .detail{ color: var(--text-soft); font-size: 13px; }

/* ============ MODAL (bottom sheet on mobile) ============ */
.modal{
  position: fixed; inset: 0;
  background: rgba(20,30,60,.55);
  display: flex; align-items: flex-end;
  z-index: 50;
}
.modal-box{
  background: var(--surface);
  width: 100%; max-height: 92vh;
  border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  animation: slideUp .25s ease;
}
@keyframes slideUp{ from{ transform: translateY(100%); } to{ transform: translateY(0); } }
.modal-head{
  padding: 18px 18px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: relative;
}
.modal-head::before{
  content:''; position:absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 4px; border-radius: 2px; background: var(--border);
}
.modal-head h3{ margin: 0; font-size: 17px; font-weight: 600; }
.modal-body{ padding: 16px; overflow: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-foot{
  padding: 12px 16px; border-top: 1px solid var(--border);
  display: flex; gap: 8px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.modal-foot .btn{ flex: 1; }

/* ============ ALERT / TOAST ============ */
.alert{
  padding: 12px 14px; border-radius: 10px; font-size: 14px;
  border: 1px solid;
}
.alert.err{ background:#fee2e2; color:#991b1b; border-color:#fecaca; }
.alert.ok { background:#d1fae5; color:#065f46; border-color:#a7f3d0; }
.alert.info{ background:#dbeafe; color:#1e3a8a; border-color:#bfdbfe; }

.toast{
  position: fixed; left: 50%;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #101a2c; color:#fff;
  padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 100;
  font-size: 14px; max-width: calc(100% - 32px);
  text-align: center;
  animation: toastIn .25s ease;
}
@keyframes toastIn{ from{ transform: translate(-50%, 100%); opacity: 0; } to{ transform: translate(-50%, 0); opacity: 1; } }
.toast.err{ background: var(--danger); }
.toast.ok { background: var(--accent); }

/* ============ DESKTOP (>= 768px) ============ */
@media (min-width: 768px){
  body{ font-size: 14px; }
  .app{
    flex-direction: row;
    padding-bottom: 0;
  }
  .sidebar{
    position: sticky; top: 0;
    width: 240px; height: 100vh;
    flex-direction: column;
    background: #101a2c; color: #dde3ef;
    border-top: 0; border-right: 1px solid rgba(255,255,255,.08);
    padding-bottom: 0;
    box-shadow: none;
  }
  .brand{
    display:flex; gap: 10px; align-items: center;
    padding: 18px; border-bottom: 1px solid rgba(255,255,255,.08);
  }
  .brand strong{ display: block; font-size: 14px; }
  .brand small { color: #8b95a8; font-size: 11px; display: block; }
  .nav{
    flex: 1; flex-direction: column;
    padding: 10px 8px; gap: 2px;
    overflow-x: visible;
  }
  .nav-item{
    flex-direction: row;
    color: #c2cbe0;
    padding: 10px 12px; border-radius: 8px;
    font-size: 13px; text-align: left;
    justify-content: flex-start;
    min-height: 40px; min-width: auto;
  }
  .nav-item:hover{ background: rgba(255,255,255,.06); color:#fff; }
  .nav-item.active{ background: var(--primary); color:#fff; }
  .nav-item .icon{ font-size: 16px; width: 18px; text-align: center; }
  .nav-item span:last-child{ flex: 1; }
  .sidebar-footer{
    display: flex; flex-direction: column; gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
  }
  .user-card{
    display: flex; gap: 10px; align-items: center;
    background: rgba(255,255,255,.05);
    padding: 8px 10px; border-radius: 8px;
  }
  .user-card .avatar{
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 700;
  }
  .user-card strong{ display: block; font-size: 13px; }
  .user-card small{ color: #8b95a8; font-size: 11px; }
  .btn.ghost{ color: #c2cbe0; border-color: rgba(255,255,255,.18); }
  .btn.ghost:hover{ background: rgba(255,255,255,.08); color: #fff; }

  .main{ flex: 1; min-width: 0; }
  .topbar{ height: auto; padding: 14px 24px; }
  .topbar h2{ font-size: 18px; }
  .view-area{ padding: 22px 24px; }

  /* tables look like real tables on desktop */
  .table{ display: table; }
  .table thead{ display: table-header-group; }
  .table tbody{ display: table-row-group; }
  .table tr{ display: table-row; padding: 0; }
  .table th, .table td{
    display: table-cell;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
  }
  .table td{ font-size: 13px; }
  .table td:first-child{ font-size: 13px; margin: 0; }
  .table td:before{ display: none; }
  .table th{
    font-weight: 600; color: var(--text-soft); background: var(--surface-2);
    font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
    text-align: left;
  }
  .table tbody tr:hover{ background: var(--surface-2); }
  .table td.actions{
    display: table-cell; border-top: 0; padding-top: 10px; margin-top: 0;
    text-align: right;
  }
  .table td.actions .btn{ flex: none; min-width: 0; }

  .cards{ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }

  .toolbar{ flex-direction: row; align-items: center; flex-wrap: wrap; }
  .toolbar input, .toolbar select{ width: auto; min-width: 220px; flex: 1; }
  .form .row{ display: grid; grid-template-columns: 1fr 1fr; }

  .modal{
    align-items: center; justify-content: center;
    padding: 24px;
  }
  .modal-box{
    width: 600px; max-width: 100%;
    max-height: 90vh;
    border-radius: 12px;
    animation: none;
  }
  .modal-head::before{ display: none; }
  .modal-head{ padding: 14px 18px; }
  .modal-foot{ justify-content: flex-end; padding-bottom: 12px; }
  .modal-foot .btn{ flex: none; }

  .toast{ bottom: 22px; right: 22px; left: auto; transform: none; max-width: 320px; }
}

/* ============ CHECKBOX (form .check) ============ */
.form label.check{
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.form label.check input[type=checkbox]{
  width: 22px; height: 22px;
  padding: 0; margin: 0;
  -webkit-appearance: auto;
  appearance: auto;
  accent-color: var(--primary);
}
.form label.check span{
  font-size: 14px; color: var(--text); font-weight: 500; text-transform: none; letter-spacing: 0;
}

/* ============ DOC ROW (mobile-friendly attachment list) ============ */
.doc-row{ display: flex; align-items: center; gap: 12px; }
.doc-info{ flex: 1; min-width: 0; }
.doc-info strong{ display: block; font-size: 15px; }
.doc-info small{ color: var(--text-soft); font-size: 12px; }
.thumb{
  flex-shrink: 0;
  width: 56px; height: 56px;
  border-radius: 8px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  text-decoration: none;
  color: var(--text-soft);
  font-size: 11px; font-weight: 700;
  border: 1px solid var(--border);
}
.thumb img{ width: 100%; height: 100%; object-fit: cover; }
.thumb.pdf{ background: #fef3c7; color: #92400e; }
.thumb.file{ background: var(--surface-2); color: var(--text-soft); }
.thumb-placeholder{
  flex-shrink: 0; width: 56px; height: 56px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}

/* hide on mobile (already shown via doc-row), show on desktop */
.d-desktop{ display: none !important; }
@media (min-width: 768px){
  .d-desktop{ display: table-cell !important; }
  .doc-row .doc-info small{ display: none; }
}

/* ============ TILES (dashboard) — botões clicáveis ============ */
.card.tile{
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  width: 100%;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  position: relative;
}
.card.tile::after{
  content: "›";
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-soft); font-size: 22px; font-weight: 300;
}
.card.tile:hover{ border-color: var(--primary); }
.card.tile:active{
  transform: scale(.97);
  box-shadow: 0 1px 4px rgba(47,107,255,.25);
}
.card.tile .value{ color: var(--primary); }

/* Feedback de toque para linhas-card das tabelas (mobile) */
@media (max-width: 767px){
  .table tr{ cursor: pointer; transition: background .12s ease; }
  .table tr:active{ background: var(--surface-2); }
  /* impede que o tap na linha "consuma" o tap dos botoes de acao */
  .table td.actions .btn{ pointer-events: auto; }
}

/* ============ BACK BUTTON ============ */
.back-btn{
  flex-shrink: 0;
  margin-left: -6px;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}
.back-btn:active{ background: var(--surface-2); }
